Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

escape and include

{# no work #}

{# index.volt #}
{% autoescape true %}
  {% include "my_file" with [ 'object': my_object ] %}
{% endautoescape %}

{# my_file.volt #}
<div>{{ object.id }}</div>
{# work #}

{# index.volt #}
{% include "my_file" with [ 'object': my_object ] %}

{# my_file.volt #}
{% autoescape true %}
  {{ '<div>' }}{{ object.id }}{{ '</div>' }}
{% endautoescape %}

I need the first option, how to do?

Tried through $compiler->addFunction(), but the $exprArgs return string.



6.2k
edited Apr '16

Does partial work?

{# no work #}

{# index.volt #}
{% autoescape true %}
  {% partial ("my_file", [ 'object': my_object ]) %}
{% endautoescape %}

{# my_file.volt #}
<div>{{ object.id }}</div>


6.2k

Btw, include copies the (compiled) content into your view, so autoescape should not work. Partial should work because content is compiled after partial file is put into the view.



325
{{ partial (...) }}

doesn't work

works as include, It displays 1 instead of <div>1</div>

there is an:

{# my_file.volt #}

{% if data_escape %}
{% autoescape true %}
...
{% endautoescape %}
{% else %}
...
{% endif %}

there are no other?



325
Accepted
answer

I wrote helper and return through the htmlspecialchars + partial

return htmlspecialchars($di->get('view')->getPartial('my_file', ['object' => $object]));