简体   繁体   English

Magento 2:如何为单个商店使用自定义模块覆盖核心模板?

[英]Magento 2: How do I override a core template using a custom module for a single store?

I want to customize the /checkout/success template file ( success.phtml ). 我想自定义/checkout/success模板文件( success.phtml )。 I have a custom module built that overrides the core vendor/magento/module-checkout/Block/Checkout/Onepage/Success block and adds data into prepareData() . 我建立了一个自定义模块,该模块将覆盖核心vendor/magento/module-checkout/Block/Checkout/Onepage/Success块,并将数据添加到prepareData() If I add the template file within my module ( Vendor\\Module\\view\\frontend\\templates\\success.phtml ), everything is great: no problem loading and rendering the additional data in the phtml. 如果将模板文件添加到模块中( Vendor\\Module\\view\\frontend\\templates\\success.phtml ),则一切都很好:在phtml中加载和呈现其他数据没有问题。

The problem is that I only want to set the override for a single store - so normally I would put the new template in app/design/frontend/[theme]/[themename]/Magento_Checkout/templates/success.phtml - and expect that that would trump the core version, but that doesn't seem to be working if I have a module overriding that template already. 问题是我只想为单个商店设置替代-因此通常我会将新模板放在app/design/frontend/[theme]/[themename]/Magento_Checkout/templates/success.phtml ,并期望这会胜过核心版本,但是如果我已经有一个模块可以覆盖该模板,那似乎就无法正常工作。

How do you configure a theme/store level template using a custom module Block, and let other stores use the core template? 如何使用自定义模块Block配置主题/商店级别模板,并让其他商店使用核心模板?

Figured it out: within the theme's directory structure, you need to specify the extended module name, not the core module name. 弄清楚了:在主题的目录结构中,您需要指定扩展模块名称,而不是核心模块名称。 You still need to have a template file within the module with the block extension (which seems clunky - why not just use core by default?) so I copied the core template to the module, then was able to specify the theme level template as app/design/frontend/[themeparent]/[themename]/Vendor_Module/template/success.phtml rather than app/design/frontend/[themeparent]/[themename]/Magento_Checkout/templates/success.phtml . 您仍然需要在模块中使用带有扩展名的模块文件(这看起来很笨拙-为什么默认不使用core?),所以我将核心模板复制到了模块中,然后能够将主题级别的模板指定为app/design/frontend/[themeparent]/[themename]/Vendor_Module/template/success.phtml而不是app/design/frontend/[themeparent]/[themename]/Magento_Checkout/templates/success.phtml

All themes use the extended modules template (copy of core) and the specific theme uses it's own template. 所有主题均使用扩展模块模板(核心副本),特定主题使用其自己的模板。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM