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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀