Вопрос

I have an given template file with following content:

Welcome, {{ user }}

In my PHP File I load this content by:

$welcome = file_get_contents(APPPATH . 'classes/Plugins/Core/testplugin/view/frontend/index.html');

So that's in template:

"Welcome, {{ user }}"

Now, if I give this content into my template:

$twig->welcome = $welcome;
$twig->user = "Tom";

Template output (html):

{{ welcome }}

Template output (browser):

Welcome, {{ user }}

My problem: Template engine won't replace my user given in twig string!

Any ideas? I tried using following filters:

{{ welcome|nl2br|raw }}

Это было полезно?

Решение

So you have a string in your template which in itself is a template. Then you need to tell Twig to treat your template variable as a template, otherwise it'll just treat it as string. For this there's the template_from_string function.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top