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条)

报告相同问题?

悬赏问题

  • ¥15 socket通信实现多人聊天室疑惑
  • ¥15 DEV-C++编译缺失
  • ¥33 找熟练码农写段Pyhthon程序
  • ¥100 怎么让数据库字段自动更新
  • ¥15 antv g6 力导向图布局
  • ¥15 quartz框架,No record found for selection of Trigger with key
  • ¥15 锅炉建模+优化算法,遗传算法优化锅炉燃烧模型,ls-svm会搞,后面的智能算法不会
  • ¥20 MATLAB多目标优化问题求解
  • ¥15 windows2003服务器按你VPN教程设置后,本地win10如何连接?
  • ¥15 求一阶微分方程的幂级数