[英]How can i include a template from the parent theme in the current theme in Magento 2?
我正在使用Magento ver。 2.1.8。 我創建了一個新主題並繼承了購買的主題。 在父主題中,我有一個在子主題中覆蓋的模板。 如何在當前主題中包含父主題的模板? 我認為我的決定不是最佳選擇,但是我認為從父主題復制所有模板HTML是一個骯臟的解決方案。 我的解決方案是:
$templateFile = str_replace('my-theme-vendor/my-theme', 'parent_theme_vendor/parent_theme', $block->getTemplateFile());
include($templateFile);
只需將其復制到主題中即可。
Foo / Bar是兒童主題。 它的父母是珍貴/主題
復制
珍貴/主題/Magento_Catalog/templates/product/list.phtml
至
Foo / Bar / Magento_Catalog / templates / product / list.phtml
您已准備好要編輯的模板。 這是覆蓋父主題模板的最干凈的方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.