开发者

Calling macros inside variable in Twig

开发者 https://www.devze.com 2023-02-22 15:07 出处:网络
Is it possible to call a macro inside a variable using Twig templating? {# in your template #} {% macro say_hello(name) %}

Is it possible to call a macro inside a variable using Twig templating?

{# in your template #}
{% macro say_hello(name) %}
<p>Oh! Hello {{ name }}!</p>
{% endmacro %}

And...

// In your php script
$post = "Lorem ipsum... {{ _self.say_hello('name') }} ... plus ultra";

And later...

{% ...in template... %}
{{ post }}

I want to do this to allow开发者_高级运维 users to customize their blog template.

Thank you.


No, I don't thinks its possible. What you'll end up with is a just raw data from your $post variable something like this:

Lorem ipsum... {{ _self.say_hello('name') }} ... plus ultra


Currently it is possible using StringLoader extension.

See this example: http://twig.sensiolabs.org/doc/functions/template_from_string.html

0

精彩评论

暂无评论...
验证码 换一张
取 消