NotionCommotion Posted July 22, 2016 Share Posted July 22, 2016 (edited) I wish Twig to escape all variables except for row.id and row.path, and not escape the quotes or anchor tabs around each. Is this possible? Thanks <tr{{ (row.id?' data-id="'~row.id~'"')|raw }}><td>{{ row.path?'<a href="'~row.path~'" target="_blank">'|raw~row.name~'</a>'|raw:row.name }}</td><td>{{ row.size }}</td><td>{{ row.date }}</td><td><img alt="Delete File" title="Delete File" src="/lib/stdimages/icon_16/delete.png" class="vtip delete" height="16" width="16"></td></tr> Edited July 22, 2016 by NotionCommotion Quote Link to comment https://forums.phpfreaks.com/topic/301550-escaping-only-certain-variables-in-twig-ternary-operator/ Share on other sites More sharing options...
Jacques1 Posted July 22, 2016 Share Posted July 22, 2016 Use conditional template sections wrapped in {% if %} ... {% endif %} instead of assembling the HTML markup from strings. Make the template readable, not as short as possible. Quote Link to comment https://forums.phpfreaks.com/topic/301550-escaping-only-certain-variables-in-twig-ternary-operator/#findComment-1534867 Share on other sites More sharing options...
NotionCommotion Posted July 22, 2016 Author Share Posted July 22, 2016 (edited) Thanks Jacques, Yea, definitely not very readable using a ternary, and taking way too much time messing around with them. EDIT. I kept the single {{ (row.id?' data-id="'~row.id~'"')|raw }} as is as it was really simple, but change the rest to {% if %}, and it works perfect. Thanks again. Edited July 22, 2016 by NotionCommotion Quote Link to comment https://forums.phpfreaks.com/topic/301550-escaping-only-certain-variables-in-twig-ternary-operator/#findComment-1534870 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.