You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Shopware6中offcanvas-cart.html.twig模板覆盖不生效问题排查

Shopware6 模板覆盖失败的问题排查

核心错误点

1. 模板文件名拼写错误

你的模板文件路径是-pluginroot-\custom\plugins\WtMinQuanSurch\src\Resources\views\storefront\component\checkout\ovvcanvas-cart.html.twig,其中**ovvcanvas-cart拼写错误**,正确文件名应为offcanvas-cart.html.twig(多写了一个v)。Shopware会严格匹配模板路径和文件名,拼写错误会导致系统无法识别你的自定义模板,直接使用默认模板。

2. Twig语法不完整,存在未闭合的标签和逻辑块

你的自定义模板里有两处语法错误,会导致Twig解析失败:

  • {% if isCartNotEmpty %}没有对应的{% endif %},逻辑块未闭合
  • <small class="offcanvas-cart-header-count">在!!Test!!后没有闭合,HTML标签不完整

修正后的模板代码示例

{% sw_extends '@Storefront/storefront/component/checkout/offcanvas-cart.html.twig' %}

{% block component_offcanvas_cart_header_item_counter %}
    {{ parent() }}
    <small class="offcanvas-cart-header-count">!!Test!!</small>
    {% if isCartNotEmpty %}
        <div class="col-auto">
            <p>!!Test!!</p>
            <small class="offcanvas-cart-header-count">
                {{ "checkout.itemCounter"|trans({'%count%': checkoutItemCounter})|sw_sanitize }}
            </small>
        </div>
    {% endif %}
{% endblock %}

额外注意事项

  • 修正文件名后,需要清空Shopware的缓存(后台设置->系统->缓存管理),确保系统加载新的模板文件
  • 开发模式下可以开启模板调试(后台设置->系统->开发设置),方便排查模板解析错误

内容的提问来源于stack exchange,提问作者tklustig

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 17:52:36