英文:
How to apply filters on Shopware sw_include (for example: |sw_sanitize)
问题
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 %}
英文:
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 %}
答案1
得分: 3
The filters striptags
and sw_sanitize
work fairly different. striptags
removes all html tags, but keeps their content. sw_santitize
completely removes some specific tags that could potentially be harmful (like <script>
) and removes them including their contents. This is why sw_sanitize
may 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 striptags
filter actually didn't work applied to sw_include
directly. You may want to use set
to capture the contents of an include and then apply the filter on the variable.
{% set foo %}
{% sw_include '@Storefront/storefront/component/delivery-information.html.twig' %}
{% endset %}
{{ foo|striptags }}
英文:
The filters striptags
and sw_sanitize
work fairly different. striptags
removes all html tags, but keeps their content. sw_santitize
completely removes some specific tags that could potentially be harmful (like <script>
) and removes them including their contents. This is why sw_sanitize
may 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 striptags
filter actually didn't work applied to sw_include
directly. You may want to use set
to capture the contents of an include and then apply the filter on the variable.
{% set foo %}
{% sw_include '@Storefront/storefront/component/delivery-information.html.twig' %}
{% endset %}
{{ foo|striptags }}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论