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
相关产品推荐
相关产品推荐

