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

如何在购物车页面重写storefront/component/line-item/element/label.html.twig?

问题解决:Twig模板调用parent()报错

错误原因

你编写的自定义模板没有继承原Shopware模板,Twig找不到对应的父模板block,因此调用parent()时触发了这个错误。

解决步骤

在你的自定义模板开头添加Shopware模板继承语句,这样才能正确引用原模板的内容:

{% sw_extends '@Storefront/storefront/component/line-item/element/label.html.twig' %}

{% block component_line_item_label %}
    {{ parent() }}
    some custom text 
{% endblock %}

额外说明

  • 若不需要保留原模板内容,直接移除{{ parent() }},只编写自定义文本即可。
  • 确保模板文件路径符合Shopware重写规则(比如放在自定义插件的src/Resources/views/storefront/component/line-item/element/label.html.twig,或主题的对应目录下)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 14:30:55