1

I've followed a number of guides to properly setting up .less files in a custom magento theme and nothing seems to be working. I've read these threads on here:

how to automatic update file `.less` in custom theme magento2?

Unable to import custom less file in custom theme's modules in Magento2

How can I add custom less file and in a particular theme compile less file in Magento 2

and poured over this page on the magento 2 docs:

https://devdocs.magento.com/guides/v2.1/frontend-dev-guide/css-topics/css-preprocess.html

I tried making modifications in: {mythemedir}/web/css/source/_extend.less {mythemedir}/web/css/source/_extends.less {mythemedir}/web/css/source/_theme.less {mythemedir}/web/css/source/_styles.less

I've made local copies of the styles-l.less and styles-m.less from the blank (which had imports for source/_sources.less and source/_theme.less)

At this point I'm just trying to drop a simple custom class in to see that it properly gets added to the site css, but nothing I tried generates anything anywhere in the static files:

> rm -fr pub/static/frontend/Magento/custom
> php bin/magento setup:static-content:deploy -f
> php bin/magento cache:flush
> grep -r customClass pub/static
> 

I also then check by Ctrl-F5 reloading the test page with a block assigned that class and nothing.

So what the hell is necessary to get the built in .less to function properly in a custom class?

1 Answer 1

1

You must delete css file from core theme in pub/static/frontend/ var/view_preprocessed/css/frontend/

6
  • I did catch on to that one. I was clearing out the static but missing the pre_processed. But it still wasn't grabbing the content in the other files. Not sure what was going on there. I eventually just added an include right in the -l and -m files pointing to my own _custom.less in sources. It seems to work for my immediate need.
    – Scott
    Feb 14, 2019 at 15:47
  • what is the 'recommended' or 'best practice' location for the custom css? extend.less? extends.less?
    – Scott
    Feb 14, 2019 at 15:48
  • app/design/frontend/Your_name_module/Your name/web/css/source/_theme.less and you must type bin/magento setup:static-content:deploy
    – Tomalo
    Feb 14, 2019 at 22:10
  • ok, but without overriding what is already there. We are currently inheriting from Magento/blank but may inherit from another theme at some point if we can find one that does things already that we like.
    – Scott
    Feb 18, 2019 at 15:53
  • To add a new source (CSS or JS) to all pages, the configuration is done through the default_head_blocks.xml file. It is also possible to add it to a single page only through the layout file for that layout handle
    – Tomalo
    Feb 19, 2019 at 21:28

Your Answer

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

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