We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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.



12.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>


12.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.



539
{{ 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?



539
Accepted
answer

I wrote helper and return through the htmlspecialchars + partial

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