I would like to invite you to new blog post series – How To In Magento 2. I noticed that some of my Magento related posts are so popular which obviously means there is need for these kind of posts. I decided to prepare blog posts series with all learning and own experiences. Each of the post will describe different problem, error or implementation. I will not cover all aspects of Magento 2 but I will point all challenges which I meet during my daily work. My main purpose of this series is to make developers’ life easier.
Probably you are wondering who I am to teach you about Magento 2. You can read about my background in one of my previous blog posts Women In Tech – How I Have Started My Journey?
I have been leading projects as HellyHansen or OspreyLondon. I just thought in this second, it is kind of sad that developer don’t get recognition for their hard work. Anyway, that’s topic for another blog post.
I work based on best practice and high quality code. No, I don’t know everything but I am trying to learn and I would love to learn from you! Add your experiences and learnings to the comment and I will add them to this series.
SUBSCRIBE TO MAGENTO 2 NEWSLETTER!
Would you like to get information when new Magento tutorial is available?
Subscribe to the newsletter and be up to date!
Let’s start the series with quick introduction to Magento 2 Frontend. As a start I would highly recommend to every single FE developer to start with The Frontend Developer Guide. Also, please, notice, that my samples are based on blank theme (I inherit my theme from blank theme ), probably they will be slightly different for luma theme.
As a first step let’s prepare structure for your new theme. It is worth to check this documentation. Following steps are a good start for your journey.
Your structure for your new theme is ready.
Your next step is grunt installation. If you are using devbox, install grunt on your devbox.
Remember to modify file dev/tools/grunt/configs/themes.js by adding your theme.
It is really important to understand how works theme inheritance, I believe Magento documentation is enough to understand the whole process.
Please, see documentation Layout Instructions and informations how to add your own style file. Below you can find some samples of changes.
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceBlock name="advanced-search-link" remove="true"/> </body> </page>
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceBlock name="my-account-link" remove="true"/> <referenceBlock name="top.links"> <block class="Magento\Customer\Block\Account\RegisterLink" name="register-link" after="authorization-link"> <arguments> <argument name="label" xsi:type="string" translate="true">Join</argument> </arguments> </block> </referenceBlock> </body> </page>
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceBlock name="multiple-wish-list-link" remove="true" /> </body> </page>
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceContainer name="header.panel"> <block class="Magento\Cms\Block\Block" name="top-header-info"> <arguments> <argument name="block_id" xsi:type="string">top-header-info</argument> </arguments> </block> </referenceContainer> <referenceBlock name="logo"> <arguments> <argument name="logo_img_width" xsi:type="number">85</argument> <argument name="logo_img_height" xsi:type="number">43</argument> </arguments> </referenceBlock> <move element="form.subscribe" destination="footer" after="-"/> <referenceBlock name="copyright" remove="true"/> <referenceBlock name="search-term-popular-link" remove="true"/> <referenceBlock name="privacy-policy-link" remove="true"/> <referenceBlock name="sales-guest-form-link" remove="true"/> <referenceBlock name="contact-us-link" remove="true"/> <referenceBlock name="catalog-search-advanced-link" remove="true"/> <referenceBlock name='report.bugs' remove='true'/> <referenceContainer name="footer"> <block class="Magento\Cms\Block\Block" name="footer-social-media" before='-'> <arguments> <argument name="block_id" xsi:type="string">footer-social-media</argument> </arguments> </block> </referenceContainer> <referenceContainer name="footer_links"> <block class="Magento\Cms\Block\Block" name="custom-footer-links"> <arguments> <argument name="block_id" xsi:type="string">custom-footer-links</argument> </arguments> </block> </referenceContainer> </body> </page>
In order to change template, please, see documentation Templates Overview. I believe it is everything what you need to know. Let me show you some examples. Notice, that some of templates are html files.
It is a great part of the documentation – Simple way to customise theme’s styles. Notice that all your less files are in app/design/frontend/<Vendor>/<theme>/web/css/source/ directory or app/design/frontend/<Vendor>/<Module_Name>/web/css/source/ directory. There is not skin directory anymore. Let’s check some important files.
@import '_buttons_extend.less'; @import '_typography_extend.less'; @import '_navigation_extend.less';
In order to add some short theme js, you can copy file from your parent theme to your theme – app/design/frontend/<Vendor>/<theme>/web/js/theme.js and modify it.
This short blog post is only initial introduction to Magento 2 Frontend. It should give you overview of Magento 2 Frontend structure, files and processes.
I hope it can help with your journey with M2! Also feel free to give your feedback and advices. Did you find this post useful? I would be more than happy if you share it with your friends, maybe someone else will find it useful as well. Good luck!
Zaneta loves challenges so deciding about career path she has chosen typical male industry. Woman who codes. Every 1-2 years she lives in different part of the world. Gym dates is something what she specialised in. Healthy lifestyle, extreme sports and motorbikes have stolen her hear years ago.
Morning reading, reading itself, was never my strong side. I really didn't like reading so…
A good road trip is all about planning and execution, ensuring you know which locations…
Ok, let me make it straight. I have never been a morning person. I remember…
Years ago if someone would tell me that I am going to meditate I would…
The US is perhaps the world’s greatest transcontinental civilisation. It stretches all the way from…
Let’s talk a little bit about workout clothing. Let me make it clear, I am…