如何用我自己的自定义主题覆盖 magento 2 主题的 phtml?

How do I override a magento 2 theme's phtml with my own custom theme?

我正在尝试自定义 ultimo 主题(尽管这可能适用于任何 magento 主题)。我创建了一个新的自定义主题,它(使用 theme.xml)使用 Infortis/ultimo 作为父主题。

Ultimo 的路径如下 header.phtml

ultimo/default/template/page/html/header.phtml

我已经为我的主题尝试了多种不同的选项来覆盖它 - none 其中似乎有效,例如

frontend/my_theme/default/template/html/header.phtml
frontend/my_theme/default/template/page/html/header.phtml

有没有人有什么想法?

使用主题路径覆盖您的模板

喜欢app/design/<Vendor>/<Package>/<Module_Package>/templates/your.phtml

看来你用的是 magneto 1.X(根据你的参考代码)

在 Magento 中 1.X

首先,您应该在后台配置新的 package/theme

System -> Configuration -> Design -> Package = my_theme

Themes: default (no change should be necessary)

现在可以修改文件了header.phtml

app\design\frontend\my_theme\default\template\html\header.phtml

在 Magento 2 中

app\design\frontend\<VENDOR_NAME>\<THEME_NAME>\Magento_Theme\templates\html\header.phtml

在您的 theme.xml 中,您将父项设置为 Infortis/ultimo

  <parent>Infortis/ultimo</parent>

就像 /Infortis/ultimo/模板/页面/html/header.phtml

/Custom/Theme/template/page/html/header.phtml

请清除并刷新缓存

并部署并授予权限

sudo php bin/magento cache:clean

sudo php bin/magento cache:flush

sudo php bin/magento setup:static-content:deploy

sudo chmod 777 -R var/ pub/media pub/static

注意:不要忘记将它们存储为您自定义创建的主题..

registration.php代码

\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::THEME,
'frontend/Custom/Theme',
__DIR__

);

theme.xml

<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
<title>New Custom</title>
<parent>Infortis/ultimo</parent>
<media>
    <preview_image>media/preview.png</preview_image>
</media>