如何覆盖 Magento 2 中的 phtml 文件

How to override in phtml file in Magento 2

在 Magento 2 中,我创建了新主题并从 vendor/magento/module-theme/view/frontend/templates/html 文件夹复制 header.phtml 文件并粘贴到 app/design/frontend/mage_vender/sample(主题)/module-theme/template/html/header.phtml 文件。 我正在尝试更改 header.phtml 文件,但未显示更改。 谁能告诉我我忘记了哪一步? 我正在使用 magento 2.1.3 谢谢

我会 post phtml 和 html 文件的答案。

覆盖 phtml 个文件

例如,如果您想覆盖 site_name/vendor/magento/module-checkout/view/frontend/templates/cart/shipping.phtml,则需要将其放在 /site_name/app/design/frontend/ThemeName/default/Magento_Checkout/templates/cart/shipping.phtml

覆盖(KO)html 个文件

例如,如果你想覆盖/site_name/vendor/magento/module-checkout/view/frontend/web/template/summary/item/details.html,你需要把它放在/site_name/app/design/frontend/ThemeName/default/Magento_Checkout/web/template/summary/cart-items.html

下面

现在 html 页面可能会很麻烦,您需要确保清除浏览器的缓存。如果您使用的是最新的 google chrome,您可以检查元素转到网络选项卡,然后勾选禁用缓存,重新加载页面。这样做的原因是 HTML 页面更容易缓存。如果这不起作用,请清除您的 pub/static/frontend 文件夹。