douyanzan9145 2012-04-11 02:47
浏览 121
已采纳

如何在twig模板中添加require_once('file.php')语句?

I'm new to this symfony2 and twig so I'm not very familiar with it. I need to add a require_once(file.php) into a mytemplate.html.twig but I just don't know how to do that!! :S
The thing is that I have to add a social slider to my website which is being developed with symfony2.
The plugin's requirement is to add the require_once(file.php) statement so any ideas on how to do that ? :S This is the file.php

require_once(dirname(__FILE__) . '/common.inc.php');


DEFINE('FBLB_DEMO',true);

function fblb_slider()
{
//print_r($_REQUEST);
global $fblb_preview_options;
if (isset($_REQUEST['Preset']) && FBLB_DEMO===true && FBLB_CONFIG===0)
{
    require(dirname(__FILE__) . '/fblbconfig.inc.php');
    require_once(dirname(__FILE__) . '/config.php');
    $fblb_preview_options = array_merge((array)$fblb_options,    (array)$FBLB_Presets[$_GET['Preset']]['Options']);
}
if (isset($_REQUEST['preview']) && (FBLB_CONFIG===1 || FBLB_DEMO===true))
{
    $options = $fblb_preview_options;
}
else
{
    require_once(dirname(__FILE__) . '/config.php');
    $options = $fblb_options;
    if($options['DisableByGetParamN'] && $options['DisableByGetParamV'] && $_GET[$options['DisableByGetParamN']]==$options['DisableByGetParamV'])
    {
        return;
    }
}
if ($options['Enable'] == 1 && $options['FacebookPageURL'])
{
    require_once(dirname(__FILE__) . '/fblb_slider.php');
}
if ($options['TW_Enable'] == 1 && $options['TW_Username'])
{
    require_once(dirname(__FILE__) . '/fblb_tw_slider.php');
}
if ($options['GP_Enable'] == 1 && $options['GP_PageID'])
{
    require_once(dirname(__FILE__) . '/fblb_gp_slider.php');
}
if ($options['YT_Enable'] == 1 && $options['YT_Channel'])
{
    require_once(dirname(__FILE__) . '/fblb_yt_slider.php');
}
if ($options['LI_Enable'])
{
    require_once(dirname(__FILE__) . '/fblb_li_slider.php');
}
}
fblb_slider();
  • 写回答

2条回答 默认 最新

  • douhoulei4706 2012-04-11 21:08
    关注

    Ok guys I solved it !!! First I had to create the twig extension >_>
    I follow this guide http://www.solidwebcode.com/web-development/twig-extensions-symfony-2/ or this one in spanish http://facultia.com/blog/2011/08/08/extensiones-personalizadas-twig-proyectos-symfony2/
    I used

    Twig_Function_Method($this, 'your_method_name')  
    

    Instead of filter and it worked well !! After that I just gave execution permission to the script and that was it =D !! In the twig template you use your method like this

    {{ your_method_name(your_params) }}
    

    Thanks to everyone that tried to help !!! =D

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况