Magento2修改logo

7天成为Magento系统架构师,现在开始学习Magento全栈开发!

《Magento2.X企业级开发实战》

1.主题创建是在路径 /app/design/frontend/公司名/主题名称/

  我自己创建的路径为 app/design/frontend/Bman/castle,以下操作都在这个目录下

2.创建好自己的目录后,需要在castle主题目录下创建registration.php文件

<?php
//用于注册主题
\Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::THEME, 'frontend/Bman/castle', __DIR__ );

3.然后再castle主题目录下创建theme.xml文件

<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
    <title> Castle Theme</title>
    <parent>Magento/luma</parent>
</theme>

在此说明,magento开发都是需要继承父主题,然后进行覆盖开发。由于是学习,我这里继承的是Magento/luma默认主题

4.在核心代码路径 app/vendor/magento/theme-frontend-luma/Magento_Theme/layout/default.xml文件中可以搜索到logo的block。

 如果自己的主题中存在和父主题一样的路径,自己的主题覆盖父主题的代码。所以我们在自己的路径下创建如下:

  castle/Magento_Theme/layout/default.xml

  

<?xml version="1.0"?>
<page layout="empty" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="logo">
            <arguments>
                <argument name="logo_file" xsi:type="string">images/logo.jpg</argument>
                <argument name="logo_alt" xsi:type="string">Custom Design</argument>
                <argument name="logo_img_width" xsi:type="number">250</argument>
                <argument name="logo_img_height" xsi:type="number">30</argument>
            </arguments>
        </referenceBlock>
        <referenceBlock name="copyright" remove="true"/>
    </body>
</page>

上边代码我修改了logo,并且删除了copyright。记得图片放到路径为castle/Magento_Theme/web/images/logo.jpg, web文件夹是用来放css,js,图片的。

5.最重要的一点就是在后台,content/configuation/ 路径下,应用自己的主题

6.记得刷新缓存 bin/magento c:c

如无特殊说明或标注,任何个人或组织,复制、转载、采集本站内容请注明:
本文来源于:【Magento中文网】,并添加本文地址链接。
如未按上述操作复制或转载,本站有权追究法律责任。
若本站内容侵犯了原著者的合法权益,可联系我们进行处理。