Is there a way to use filters on the sw_include twig function?
This works:
{% sw_include '@Storefront/storefront/component/captcha/%s.html.twig'|format(capchaKey)...
I'd like to remove all tags from the include. Based on twig docu this should work:
{{ include('template.html')|striptags }}
However this does not throw any errors, but also does not apply the filter:
{% sw_include '@Storefront/storefront/component/delivery-information.html.twig'|sw_sanitize %}
The filters
striptagsandsw_sanitizework fairly different.striptagsremoves all html tags, but keeps their content.sw_santitizecompletely removes some specific tags that could potentially be harmful (like<script>) and removes them including their contents. This is whysw_sanitizemay seem to you like it doesn't do anything, because it will keep "harmless" tags like<div>,<a>and some others intact.When I tested it, the
striptagsfilter actually didn't work applied tosw_includedirectly. You may want to usesetto capture the contents of an include and then apply the filter on the variable.