6

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/

5

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.

  • i have tried several times - theme is not showing up in backend. I followed the above method, when i add registration.php - i get an error when i go to home page and the backend. – roger Feb 7 '16 at 20:42
  • @roger: Have you enabled php error hints and developer mode to see what error you're getting? – amitshree Feb 8 '16 at 4:54
  • i appreciate your help guys. Thank you. finally I was able to get it to work. I think it was my composer file causing the issue. – roger Feb 8 '16 at 16:33
  • @roger, Please tell me how you solved that? – Kowsigan Atsayam Sep 23 at 17:02
2

When you install magento2 via composer you find all modules and themes under the vendor dir.

if you want to customize the blank theme, you should create a new theme which is extending the blank theme. (For developing you can create your theme under app/design like in the github repository).

You need at least the registration.php and a theme.xml.

Best example for how to extend the blank theme is the luma theme: https://github.com/magento/magento2/tree/2.0.2/app/design/frontend/Magento/luma

You also should enable the developer mode in your webroots .htaccess file (just remove the #) https://github.com/magento/magento2/blob/develop/.htaccess#L5

The developer mode ensures that files under pub/static are created dynamically and are symlinks on your original files - so they also get the updates

Magento deploys the needed files to pub/static, thats why you find them there. You still have to develop in the theme itself.

  • got it to work!! now the new template is showing in the back end, but the CSS and JS fiels are loading. when i run the cmd, php bin/magento setup:static-content:deploy --- i get the following Compilation from source: frontend/MyStore/MyAbstract/en_US/css/styles-l.less variable @button__shadow-active is undefined in file /chroot/home/installs/xxxxxxx/html/var/view_preprocessed/css/frontend/MyStore/MyAbstract/en_US/css/source/_extends.less in _extends.less on line 37, column 30 35| } 36| &:active { 37| .lib-css(box-shadow, @button__shadow-active); 38| } 39| } 40| > – roger Feb 8 '16 at 16:38
  • oh ok, can't really help you with that one since I did not look into the less features yet. maybe you should post a new question for this – David Verholen Feb 8 '16 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.