Magento – Where to place Magento 2 Theme customizations

cssless-cssmagento2theme

I installed Magento 2 via Composer and it does not have a directory for theme in frontend. I tried to create a new theme in app/design, every time I create registration.php I get an error.

Question
Is it possible to edit the CSS file in vendor/Magento/theme-frontend-blank? Will the changes take in effect on front-end?
I am confused to where should the theme customization should be done. When I use Firebug I see that the location of the CSS files are directing me to pub/static/

Best Answer

In Magento 2, there is a term called static content deployment. You see js/css files links coming from pub/static/ directory because Magento deploys js/css files to this directory from your theme/module directory and whenever a user visits website, static files and referred/shown from pub/static/ directory.

Initially you will be developing your frontend theme in app/design/frontend/ and you can deploy static content to pub/static/frontend/ using command php bin/magento setup:static-content:deploy. During development you should delete everything inside pub/static/, var/cache/, var/page_cache/, var/generation/ and deploy you content using above command.

Here is basic theme configuration example which goes inside app/design/frontend/MyStore/MyAbstract/

theme.xml

<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
<title>Mystore</title>
<parent>Magento/blank</parent>
<media>
    <preview_image>media/preview.jpg</preview_image>
</media>
</theme>

registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::THEME,
    'frontend/MyStore/MyAbstract',
    __DIR__
);

Put preview image preview.jpg (you can change name is theme.xml) inside media directory and you should see your theme in admin section store configuration.

Related Topic