dougu3290 2017-10-19 04:43
浏览 47
已采纳

twig扩展 - php相当于twig的包含

I have a library of widgets (js and other files) which instead of writing

{% include 'path' %}

all the time I have written an extension to just include them with a function call like so:

{% widget('name') %}

So my question is how do I re implement the twig include function? Is it just a matter of returning a php include or is it a file_get_contents?

Examples:

<?php

    class Extensions 
    {
        public function widget($name) 
        {
             return include 'filepath/' . $name . '.html.twig';
             // or 
             return file_get_content('filepath/' . $name . '.html.twig');
        }
    } 

Thank you

Updated: I'm using file_get_contents and I get the following returned:

alert('FROM HERE');
// AS
alert(&#039;FROM HERE&#039;);
  • 写回答

1条回答 默认 最新

  • dongse5408 2017-10-19 04:51
    关注

    its some more they parse the templates on call

    look:

    https://github.com/twigphp/Twig/blob/2.x/lib/Twig/Extension/Core.php#L1287

    edit: file_get_contents do the job. include makes more than only output the content

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗