1

When extending Magento Luma less files in one children theme, what exactly is the name and the complete structure of the "parent" folder (mentioned at https://developer.adobe.com/commerce/frontend-core/guide/css/quickstart/customize-styles/#extend-parent-styles) ?

I find the documentation very fuzzy here and I need help with this. I only can assume at this point we don't want to add the new file _extend-child.less on core parent theme folder.

Thank you very much in advance! See below the diagram from the documentation link.

app/design/frontend/Vendor/
├── parent
│   └── web
│       └── css
│           └── source
│               ├── _extend-child.less (keep this file empty)
│               └── _extend.less
└── child
    └── web
        └── css
            └── source
                └── _extend-child.less
...

2 Answers 2

1

Since the Luma theme does not have <luma theme dir>/web/css/source/_extend.less, you don't need to do anything with Luma's theme folder, just create <your theme dir>/web/css/source/_extend.less, then your theme will extend Luma theme (and Blank theme which is the parent of Luma theme) properly.

The diagram and the case mentioned in the documentation you are mentioning are for the parent theme (called theme A) that extends theme Blank and has web/css/source/_extend.less + the child theme (called theme B) that extends theme A and has web/css/source/_extend.less

6
  • I did exactly as you said and I only get an empty var/view_preprocessed/pub/static/frontend/mynamespace/mytheme/en_US/css/source/_extend.less file. Plus, in my case my theme is the theme A (extending blank) per the case described in documentation. I remove preprocessed files then I compile the less files at server with bin/magento setup:di:compile under developer mode. Evertyhing I do is by the book and not working (my installation is mint magento 2.4.6 on php 8.2).
    – steve
    Commented Apr 1, 2023 at 3:05
  • In the original description, you mentioned that you extending Luma theme, but now you say your theme extending theme Blank, so it does not clear. I thought you are working with theme A which extends theme Blank, and does not relate to them Luma, isn't it? Anyway, you don't need to recompile code (bin/magento setup:di:compile) but remove static view files (in both var/view_preprocessed and pub/static) and re-deploy them: rm -rf var/view_preprocessed/pub/static/frontend/ && rm -rf pub/static/frontend/*/* && bin/magento s:s:d -f en_US --area frontend --theme yournamespace/yourtheme --no-parent
    – Tu Van
    Commented Apr 1, 2023 at 4:14
  • I've tested and confirmed it works on 2.4.6. i.imgur.com/EM3buYj.png
    – Tu Van
    Commented Apr 1, 2023 at 4:14
  • My theme is extending Luma (which Luma extends blank I mean). So my theme is B, extending A (Luma) which extends in its turn blank. My case is exactly the case I posted the link to. (my first comment was incorrect in this regard). You only added your new less code on newtheme/web/css/sources/_extend.less file and it works on frontend for you?
    – steve
    Commented Apr 1, 2023 at 4:29
  • @steve got it. Yep, that's it, as I said before, Luma (your parent theme) does not have web/css/source/_extend.less, so you don't need to do anything with Luma's theme folder, just create <your theme dir>/web/css/source/_extend.less. One thing need to remember is you need to remove static view files in both var/view_preprocessed and pub/static. You can run the command I mentioned above to achieve that.
    – Tu Van
    Commented Apr 1, 2023 at 5:53
0

Extending the Magento Luma theme with LESS in Magento 2 involves creating a child theme that inherits from Luma and then customizing the LESS files. Here’s a step-by-step guide to help you set this up:

Step 1: Create Your Theme Directory

First, create the directory for your custom theme. For example, let's name the vendor YourVendor and the theme yourtheme.

mkdir -p app/design/frontend/YourVendor/yourtheme

Step 2: Create theme.xml

Create the theme.xml file to define your theme and its parent.

app/design/frontend/YourVendor/yourtheme/theme.xml
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
    <title>Your Theme Title</title>
    <parent>Magento/luma</parent>
</theme>

Step 3: Create registration.php

Create the registration.php file to register your theme.

app/design/frontend/YourVendor/yourtheme/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::THEME,
    'frontend/YourVendor/yourtheme',
    __DIR__
);

Step 4: Create composer.json

Create a composer.json file for your theme.

app/design/frontend/YourVendor/yourtheme/composer.json
{
    "name": "yourvendor/yourtheme",
    "description": "Your custom theme",
    "require": {
        "php": "~7.3.0||~7.4.0||~8.1.0"
    },
    "type": "magento2-theme",
    "version": "1.0.0",
    "license": [
        "OSL-3.0",
        "AFL-3.0"
    ],
    "autoload": {
        "files": [
            "registration.php"
        ]
    }
}

Step 5: Create view.xml

Create the view.xml file for your theme's view configurations.

app/design/frontend/YourVendor/yourtheme/etc/view.xml
<view xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/view.xsd">
    <media>
        <images module="Magento_Catalog">
            <image id="category_page_list" type="thumbnail">
                <width>240</width>
                <height>300</height>
            </image>
        </images>
    </media>
</view>

Step 6: Create _extend.less

To customize the LESS files, create a _extend.less file where you can add your custom LESS code.

mkdir -p app/design/frontend/YourVendor/yourtheme/web/css/source
app/design/frontend/YourVendor/yourtheme/web/css/source/_extend.less
// Custom LESS code goes here
body {
    background-color: #f4f4f4;
}

Step 7: Create Magento_Theme/layout/default_head_blocks.xml

Override or extend the default layout to include your custom styles.

mkdir -p app/design/frontend/YourVendor/yourtheme/Magento_Theme/layout
app/design/frontend/YourVendor/yourtheme/Magento_Theme/layout/default_head_blocks.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <css src="css/styles-l.css" />
        <css src="css/styles-m.css" />
    </head>
</page>

Step 8: Deploy Static Content

After creating your theme, deploy the static content.

php bin/magento setup:static-content:deploy -f

Step 9: Clear Cache

Clear the cache to ensure your changes take effect.

php bin/magento cache:clean

Step 10: Set Your Theme as Active

Finally, set your new theme as the active theme in the Magento admin panel.

  1. Go to Content > Design > Configuration.
  2. Edit the Default Store View.
  3. In the Applied Theme dropdown, select your new theme (YourVendor/yourtheme).
  4. Click Save Configuration.

Additional Customizations

  • Custom Variables: You can create a variables.less file in app/design/frontend/YourVendor/yourtheme/web/css/source/ to define custom variables and override Luma variables.
  • Custom Components: You can create custom components or override existing ones by placing your custom LESS files in the appropriate directory.

By following these steps, you can extend the Magento Luma theme with your custom LESS styles. Make sure to test your changes thoroughly in different browsers and devices.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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