【问题标题】:How to apply filters on Shopware sw_include (for example: |sw_sanitize)如何在 Shopware sw_include 上应用过滤器(例如:|sw_sanitize)
【发布时间】:2023-02-24 03:53:47
【问题描述】:

有没有办法在 sw_include twig 函数上使用过滤器?

这有效:

{% sw_include '@Storefront/storefront/component/captcha/%s.html.twig'|format(capchaKey)...

我想从包含中删除所有标签。基于 twig docu 这应该有效:

{{ include('template.html')|striptags }}

然而,这不会抛出任何错误,但也不应用过滤器:

{% sw_include '@Storefront/storefront/component/delivery-information.html.twig'|sw_sanitize %}

【问题讨论】:

    标签: twig shopware shopware6 twig-filter


    【解决方案1】:

    过滤器 striptagssw_sanitize 的工作方式完全不同。 striptags 删除了所有的 html 标签,但是保持他们的内容。 sw_santitize完全删除一些可能有害的特定标签(如<script>)并删除它们包括他们的内容。这就是为什么 sw_sanitize 在您看来似乎什么都不做,因为它将保持“无害”标签,例如 <div><a> 和其他一些标签。

    当我测试它时,striptags 过滤器实际上没有直接应用于sw_include。您可能希望使用 set 捕获包含的内容,然后对变量应用过滤器。

    {% set foo %}
        {% sw_include '@Storefront/storefront/component/delivery-information.html.twig' %}
    {% endset %}
    {{ foo|striptags }}
    

    【讨论】:

      猜你喜欢
      • 2020-10-22
      • 2011-05-20
      • 2020-01-17
      • 1970-01-01
      • 1970-01-01
      • 2022-11-23
      • 2012-07-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多