在本篇博客中,我们将看到如何在magento2中设置一个新主题
在magento2中设置新主题非常容易。主题名称分为公司名称和实际主题名称两部分,现有主题如Magento_Luma和Magento_Blank。
如果您使用“magento2-community-edition”存储库来设置magento2,那么您将在“vendor/magento/theme-frontend-luma”中找到主题文件,但如果您习惯使用“magento2”存储库,则现有主题位于“app/design/frontend”中
步骤1
如果要创建自己的主题,请转到文件夹app/design/frontend下并创建一个新的文件夹
Magease(公司名称)然后first(主题名称),
这样您的目录结构将是app/design/frontend/Magease/first
步骤2
在主题目录中创建文件theme.xml,并添加以下代码
app/design/frontend/Magease/first/theme.xml
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd"> <title>Magease First</title> <!-- your theme's name --> <parent>Magento/blank</parent> <!-- the parent theme, in case your theme inherits from an existing theme -- > <!-- <media> <preview_image>media/preview.jpg</preview_image> </media> --> <!-- Here you can put a preview image of your theme. If you don't have a preview image comment it else it gives an error --> </theme>
步骤3
在主题目录中创建文件registration.php
<?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::THEME, 'frontend/Magease/first', __DIR__ );
步骤4 - 可选
创建componser.json文件并添加以下代码
{ "name": "magease/first", "description": "N/A", "require": { "php": "~5.5.0|~5.6.0|~7.0.0", "magento/theme-frontend-blank": "100.0.*", "magento/framework": "100.0.*" }, "type": "magento2-theme", "version": "100.0.1", "license": [ "OSL-3.0", "AFL-3.0" ], "autoload": { "files": [ "registration.php" ] } }
步骤5
在这个阶段,应该已经安装了空主题
Stores -> General -> Design -> Design Theme,你的主题可以在这里看到
故障排除:如果您收到任何错误,请确保所有权限都正确并且您已按照博客内容进行操作