如何在购物车页面重写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
相关产品推荐
相关产品推荐

