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

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

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?