Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 解析细枝中的可变内容_Php_Templates_Twig_Kohana - Fatal编程技术网

Php 解析细枝中的可变内容

Php 解析细枝中的可变内容,php,templates,twig,kohana,Php,Templates,Twig,Kohana,我有一个包含以下内容的给定模板文件: 欢迎,{{user}} 在我的PHP文件中,我通过以下方式加载此内容: $welcome = file_get_contents(APPPATH . 'classes/Plugins/Core/testplugin/view/frontend/index.html'); 这就是模板: $twig->welcome = $welcome; $twig->user = "Tom"; 欢迎,{{user}} 现在,如果我将此内容添加到模板中: $t

我有一个包含以下内容的给定模板文件:

欢迎,{{user}}

在我的PHP文件中,我通过以下方式加载此内容:

$welcome = file_get_contents(APPPATH . 'classes/Plugins/Core/testplugin/view/frontend/index.html');
这就是模板:

$twig->welcome = $welcome;
$twig->user = "Tom";
欢迎,{{user}}

现在,如果我将此内容添加到模板中:

$twig->welcome = $welcome;
$twig->user = "Tom";
模板输出(html):

{{欢迎}

模板输出(浏览器):

欢迎,{{user}}

我的问题:模板引擎将不会取代我的用户给定的细枝字符串

有什么想法吗?我尝试使用以下过滤器:

{{欢迎| nl2br | raw}


所以在模板中有一个字符串,它是一个模板。然后,您需要告诉Twig将模板变量视为模板,否则它只会将其视为字符串。对于这一点,.

您的模板似乎没有被解析。你在哪里调用
$twig->render()
?我想,现在哪里都没有。如果我只使用{{user}},我有正确的输出。字符串值似乎不接受其中的任何内容。。可能有意思,太棒了!非常感谢你!