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

时间:2017-11-12 13:50:03

标签: php magento magento2 theming

我试图自定义ultimo主题(虽然这可能适用于任何magento主题)。我创建了一个新的自定义主题(使用theme.xml)使用Infortis / ultimo作为它的父级。

Ultimo有以下路径:header.phtml

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

我已经为我的主题尝试了许多不同的选项来覆盖这一点 - 但似乎没有任何选择。例如。

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

有没有人有任何想法?

3 个答案:

答案 0 :(得分:1)

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

  <parent>Infortis/ultimo</parent>

就像 /Infortis/ultimo/template/page/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>

答案 1 :(得分:0)

使用主题路径覆盖模板

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

答案 2 :(得分:0)

您似乎正在使用磁铁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