If template_from_string
is inside {% macro ... %}
string is not parsed.
Example of may code:
example.yaml
items:
item1: item1
item2: |
{{ AI }} lorem ipsum dolor sit amet...
php function
function AI() {
return 'AI<span class="ai-tm">™</span>';
}
Timber function.php
// Global $context
$context['AI'] = AI();
Twig
{# If outside macro, template_from_string parses ok #}
<pre>dump(include(template_from_string(items.item2)))</pre>
{% macro example_macro(items) %}
{# items is php array parsed from yaml file
and passed as parameter to macro #}
{% for item in items %}
<p>{{ include(template_from_string(item)) }}</p>
{% endfor %}
{% endmacro %}
Results:
{# Notices that {{ AI }} isn't parsed #}
<p>lorem ipsum dolor sit amet...</p>