如何在Shopware的sw_include上应用过滤器(例如:|sw_sanitize)?

huangapple go评论76阅读模式
英文:

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 }}

huangapple
  • 本文由 发表于 2023年2月23日 23:43:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/75547120.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定