Joomla LESS: Difference between revisions

From Joomla! Documentation

m spelling suite/suit
Cmb (talk | contribs)
Several markup changes. URL corrections. Changes for Words2Watch compliance.
 
Line 3: Line 3:
<translate>
<translate>
<!--T:1-->
<!--T:1-->
Most of the Joomla 3.0 default template stylesheets are written using [[wikipedia:LESS_(stylesheet_language)|LESS]] and then compiled to generate the [[wikipedia:CSS|CSS]] files.
Most of the Joomla 3.0 default template style sheets are written using [[wikipedia:LESS_(stylesheet_language)|LESS]] and then compiled to generate the [[wikipedia:CSS|CSS]] files.
</translate>
</translate>


<translate>
<translate>
== Where can you find the .less stylesheets and compiler? == <!--T:2-->
== Where Can You Find the ''.less'' Style Sheets and Compiler? == <!--T:2-->
</translate>
</translate>


<translate>
<translate>
<!--T:3-->
<!--T:3-->
The <code>.less</code> building blocks are located in <code>media/jui/less/</code>. The template specific <code>.less</code>files are located in <code>templates/&lt;templates&gt;/less/</code>.
The ''.less'' building blocks are located in ''media/jui/less/''. The template-specific ''.less'' files are located in ''templates/&lt;templatename&gt;/less/''.


<!--T:4-->
<!--T:4-->
The CSS generation wrapper script, LESS compiler, and other similar build tools are located in the <code>build/</code> directory of the Joomla source located on GitHub. Refer to [[S:MyLanguage/Git_for_Coders|Git for Coders]] for more information on using GitHub. The build directory is only available from the Joomla source, it is not included in an official Joomla release.
The CSS generation wrapper script, LESS compiler, and other similar build tools are located in the ''build/'' directory of the Joomla source located on GitHub. Refer to [[S:MyLanguage/Git_for_Coders|Git for Coders]] for more information on using GitHub. The build directory is only available from the Joomla source. It is not included in an official Joomla release.
</translate>  
</translate>


<translate>
<translate>
== How to re-generate the CSS stylesheets == <!--T:5-->
== How to Regenerate the CSS Style Sheets == <!--T:5-->
</translate>
</translate>


<translate>
<translate>
<!--T:6-->
<!--T:6-->
To re-generate all the CSS files from a Joomla core distribution, you will need to execute the generation scripts as a [[wikipedia:Command-line_interface|CLI application]].
To regenerate all the CSS files from a Joomla core distribution, execute the generation scripts as a [[wikipedia:Command-line_interface|CLI application]]:</translate>
 
<!--T:7-->
For example:
</translate>


<pre>cd joomla-cms/build
<pre>cd joomla-cms/build
Line 35: Line 31:


<translate>
<translate>
== Compiling your own LESS files for your template == <!--T:8-->
== Compiling Your Own LESS Files For Your Template == <!--T:8-->


<!--T:9-->
<!--T:9-->
To compile less files for your own template, you will need to take a copy of the <code>generatecss.php</code> script and adjust it to suit your template.
To compile LESS files for your own template, you will need to take a copy of the ''generatecss.php'' script and adjust it to suit your template.


<!--T:10-->
<!--T:10-->
Alternatively you can use a LESS Compiler plugin which compiles your .less files automatically on page reload:
Alternatively you can use a [https://extensions.joomla.org/extension/miscellaneous/development/less-compiler/ LESS Compiler plugin] that compiles your ''.less'' files automatically on page reload.
http://extensions.joomla.org/extensions/miscellaneous/development/22424


<!--T:11-->
<!--T:11-->
More alternatives and tools on a recent Joomla! Magazine article:
More alternatives and tools are to be found in [https://magazine.joomla.org/all-issues/issue-may-2013/tools-to-do-less a Joomla! Magazine article].
http://magazine.joomla.org/issues/issue-may-2013/item/1289-tools-to-do-less
</translate>
</translate>


<translate>
<translate>
== Not all LESS compilers are equal == <!--T:12-->
== Not All LESS Compilers are Equal == <!--T:12-->
The LESS compiler used for the Joomla core for code style consistency is obtained from [http://leafo.net/lessphp leafo.net/lessphp].
The LESS compiler used for the Joomla core for code style consistency is obtained from [https://leafo.net/lessphp/ leafo.net/lessphp].


<!--T:13-->
<!--T:13-->
If you're working on your own template you can use any compiler you like.
If you're working on your own template, use any compiler you like.
</translate>
</translate>


<translate>
<translate>
== Difference CSS vs LESS imports == <!--T:14-->
== Difference CSS vs LESS Imports == <!--T:14-->


<!--T:15-->
<!--T:15-->
The main .less file and starting point e.g. in protostar is located in <pre>/templates/protostar/less/template.less</pre>
The main ''.less'' file and starting point in Protostar is located in ''/templates/protostar/less/template.less''.
If you open that file you will find many @imports in this file - imports from many different places. Unlike imports in CSS, imports in LESS get compiled to a single CSS file. This will result in fewer http requests and speed your site up.
If you open that file you will find many ''@imports''—imports from many places. Unlike imports in CSS, imports in LESS get compiled to a single CSS file. This results in fewer HTTP requests and speeds up your site.
</translate>
</translate>


<translate>
<translate>
== From existing CSS to LESS / import CSS files == <!--T:16-->
== From Existing CSS to LESS/Import CSS Files == <!--T:16-->


<!--T:17-->
<!--T:17-->
You may want to add your existing CSS files and classes to your LESS powered template or start with what you have. All CSS declarations are compatible with LESS so you can just rename your .css files to .less and you can compile and use them. You can then step by step make use of the great dynamic features LESS has to offer: variables, mixins, operations and functions. See http://www.lesscss.org
You may want to add your existing CSS files and classes to your LESS-powered template or start with what you have. All CSS declarations are compatible with LESS so just rename your ''.css'' files to ''.less'' and you can compile and use them. You can then make use of the great dynamic features LESS has to offer: variables, mixins, operations and functions. See the [https://lesscss.org/ lesscss.org website].
</translate>
</translate>


<translate>
<translate>
<!--T:18-->
<!--T:18-->
Notice: the examples below reference the default Protostar template for clarity. Your paths may be different.  
Notice: The examples below reference the default Protostar template for clarity. Your paths may be different.
Notice: If you want to customize Protostar template it is a good idea to copy the template and customize it afterwards - so that Joomla! updates do not overwrite your customizations.
 
Notice: If you want to customize the Protostar template, copy the template and customize it afterwards so that Joomla! updates do not overwrite your customizations.
</translate>
</translate>


<translate>
<translate>
=== Option 1: import your .css as .less files === <!--T:19-->
=== Option 1: Import Your ''.css'' as ''.less'' Files === <!--T:19-->
(a little bit work but worth it, imho)
(A little bit work but worth it.)
</translate>
</translate>


<translate>
<translate>
<!--T:20-->
<!--T:20-->
Now lets assume you want to include your custom files and get them parsed by LESS compiler - you do NOT need to rewrite your .css to LESS because plain .css works as well. The only thing you have to do is to rename your .css files to .less and add an @import statement into above mentioned main /templates/protostar/less/template.less
Now let's assume you want to include your custom files and get them parsed by LESS compiler. You do '''not''' need to rewrite your ''.css'' to LESS because plain ''.css'' works as well. The only thing you have to do is to rename your ''.css'' files to ''.less'' and add an @import statement into ''/templates/protostar/less/template.less''.
</translate>
</translate>


<translate>
<translate>
<!--T:21-->
<!--T:21-->
I assume you put your custom .css files renamed to .less into the /templates/protostar/less folder. Now you open /templates/protostar/less/template.less and at the bottom of the file you import your custom .less files so that they override existing declarations:
You put your custom ''.css'' files renamed to ''.less'' into the ''/templates/protostar/less'' folder. Now open ''/templates/protostar/less/template.less'' and at the bottom of the file, import your custom ''.less'' files so that they override existing declarations:
</translate>
</translate>


Line 101: Line 96:
<translate>
<translate>
<!--T:22-->
<!--T:22-->
If you now compile your main template.less file you end up with one main template.css optimized and minified (if you wish). You also reduced your http requests and the site should load faster. Now you can start step by step in your custom.less files to use less variables and other cool stuff http://lesscss.org has to offer.
If you now compile your main ''template.less'' file, you end up with one main ''template.css'' optimized and minified (if you wish). You also reduced your HTTP requests and the site should load faster. Now you can start in your ''custom.less'' files to use LESS variables and other features [https://lesscss.org/# lesscss.org] has to offer.
</translate>
</translate>


<translate>
<translate>
=== Option 2: just import your .css / does not work for overriding === <!--T:23-->
=== Option 2: Just Import Your ''.css''/Does Not Work for Overriding === <!--T:23-->
In /templates/protostar/less/template.less just import your .css files and they will be included as imports into main template.css:
In ''/templates/protostar/less/template.less'', import your ''.css'' files and they will be included as imports into main ''template.css'':
</translate>
</translate>


Line 117: Line 112:
<translate>
<translate>
<!--T:24-->
<!--T:24-->
But this way you do not get any optimization. And a big issue is that this import is always on top before other declarations - so you can't override an existing declaration.
This way you do not get any optimization. Another big issue is that this import is always on top before other declarations so you can't override an existing declaration.


<!--T:25-->
<!--T:25-->
More information: http://lesscss.org/#usage (Section Importing)
More information: [https://lesscss.org/# lesscss.org]
</translate>
 
<translate>
== References == <!--T:26-->
 
<!--T:27-->
http://kyleledbetter.com/jui/less/ - Example of building your own template.less
</translate>
</translate>



Latest revision as of 22:48, 13 November 2022

Most of the Joomla 3.0 default template style sheets are written using LESS and then compiled to generate the CSS files.

Where Can You Find the .less Style Sheets and Compiler?

The .less building blocks are located in media/jui/less/. The template-specific .less files are located in templates/<templatename>/less/.

The CSS generation wrapper script, LESS compiler, and other similar build tools are located in the build/ directory of the Joomla source located on GitHub. Refer to Git for Coders for more information on using GitHub. The build directory is only available from the Joomla source. It is not included in an official Joomla release.

How to Regenerate the CSS Style Sheets

To regenerate all the CSS files from a Joomla core distribution, execute the generation scripts as a CLI application:

cd joomla-cms/build
c:\xampp\php\php.exe generatecss.php

Compiling Your Own LESS Files For Your Template

To compile LESS files for your own template, you will need to take a copy of the generatecss.php script and adjust it to suit your template.

Alternatively you can use a LESS Compiler plugin that compiles your .less files automatically on page reload.

More alternatives and tools are to be found in a Joomla! Magazine article.

Not All LESS Compilers are Equal

The LESS compiler used for the Joomla core for code style consistency is obtained from leafo.net/lessphp.

If you're working on your own template, use any compiler you like.

Difference CSS vs LESS Imports

The main .less file and starting point in Protostar is located in /templates/protostar/less/template.less. If you open that file you will find many @imports—imports from many places. Unlike imports in CSS, imports in LESS get compiled to a single CSS file. This results in fewer HTTP requests and speeds up your site.

From Existing CSS to LESS/Import CSS Files

You may want to add your existing CSS files and classes to your LESS-powered template or start with what you have. All CSS declarations are compatible with LESS so just rename your .css files to .less and you can compile and use them. You can then make use of the great dynamic features LESS has to offer: variables, mixins, operations and functions. See the lesscss.org website.

Notice: The examples below reference the default Protostar template for clarity. Your paths may be different.

Notice: If you want to customize the Protostar template, copy the template and customize it afterwards so that Joomla! updates do not overwrite your customizations.

Option 1: Import Your .css as .less Files

(A little bit work but worth it.)

Now let's assume you want to include your custom files and get them parsed by LESS compiler. You do not need to rewrite your .css to LESS because plain .css works as well. The only thing you have to do is to rename your .css files to .less and add an @import statement into /templates/protostar/less/template.less.

You put your custom .css files renamed to .less into the /templates/protostar/less folder. Now open /templates/protostar/less/template.less and at the bottom of the file, import your custom .less files so that they override existing declarations:

@import "modules.less";
@import "components.less";
@import "articles.less";

If you now compile your main template.less file, you end up with one main template.css optimized and minified (if you wish). You also reduced your HTTP requests and the site should load faster. Now you can start in your custom.less files to use LESS variables and other features lesscss.org has to offer.

Option 2: Just Import Your .css/Does Not Work for Overriding

In /templates/protostar/less/template.less, import your .css files and they will be included as imports into main template.css:

@import "../css/modules.css";
@import "../css/components.css";
@import "../css/articles.css";

This way you do not get any optimization. Another big issue is that this import is always on top before other declarations so you can't override an existing declaration.

More information: lesscss.org