Calling macros inside variable in Twig
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
精彩评论