简体   繁体   中英

Nested braces in twig (symfony)

I am trying to set a data- attribute for a save button, but it doesn't like the nested braces. I'm getting an error on the "###THIS LINE" line.

 {% for file in payment.files %}
     <br>
     <li>
         ...
         ... etc...
         ... 
         {{ form_widget(file.save, {'attr':{'data-file-id': {{ file.id}} } }) }} ###THIS LINE

     </li>
{% endfor %}

The error I am getting is: A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "punctuation" of value "{".

I guess it doesn't like the nested braces.

Any help is greatly appreciated.

尝试将file.id转换为字符串:

{{ form_widget(file.save, {'attr':{'data-file-id': file.id.__toString } }) }}

去尝试一下:

{{ form_widget(file.save, {'attr':{'data-file-id': file.id } }) }}

尝试:

{{ form_widget(file.save, {'attr': {'data-file-id': file.id|string } }) }}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM