I need to escape those double quotes in post_data.postCaption1 as below. But it seems not working. How to do it?
<div class="form-group">
{% autoescape %}
{{ form_widget(blog_form.post_caption1, { 'attr': {'class': 'form-control', 'placeholder': 'Enter caption for image 1', 'value': post_data.postCaption1|raw } }) }} {% endautoescape %}
{{ form_errors(blog_form.post_caption1) }}
</div>
答案 0 :(得分:0)
If you use the raw filter, post_data.postCaption1 won't be escaped because raw is the last filter applied to it:
{% autoescape %}
{{ var|raw }} {# var won't be escaped #}
{% endautoescape %}
You can try:
{% set strategy = 'html' %}
{% autoescape %}
{{ form_widget(blog_form.post_caption1, { 'attr': {'class': 'form-control', 'placeholder': 'Enter caption for image 1', 'value': post_data.postCaption1|escape(strategy) } }) }}
{% endautoescape %}
{{ form_errors(blog_form.post_caption1) }}