1. The Drupal & Less Combo
By: Albert S. Causing
acausing@drupalph.org
Date: October 27, 2012
2. 1. What is CSS
2. What is LESS CSS
3. Less CSS:
Variables
Mixins
Nested Rules
Functions & Operations
4. Code samples
5. Drupal & Less
Drupal Less Module Installation
6. Q&A and Live Example
2 of 16
3. www.drupalph.org
What is CSS
Cascading Style Sheets (CSS) is a style sheet language used for
describing the presentation semantics (the look and formatting) of a
document written in a markup language. Its most common application
is to style web pages written in HTML and XHTML.
CSS Usage
• Prior to CSS, nearly all of the presentational attributes of HTML
documents were contained within the HTML markup;
• HTML element attributes had to be explicitly descripted, often
repeatedly, within the HTML.
• CSS allows authors to move much of that information to another
file, the style sheet, resulting in considerably simpler HTML.
- Wikipedia
3 of 16
4. www.drupalph.org
What is LESS
• LESS was developed by Alexis Sellier,
• The dynamic stylesheet language.
• It is influenced by Sass and has influenced the newer "SCSS" syntax
of Sass, which adapted its CSS-like block formatting syntax.
• The indented syntax of LESS is a nested metalanguage, as valid
CSS is valid LESS code with the same semantics.
• LESS provides the following
mechanisms: variables, nesting, mixins, operators and functions.
4 of 16
25. www.drupalph.org
DRUPAL + LESS
http://www.drupal.org/project/less
This module will automatically process any LESS files
that are added using drupal_add_css or added through
your theme's .info file.
Add your files just like any other css file, just with .less as
the extension, and they will be automatically processed.
25 of 16
26. www.drupalph.org
LESS Module Installation
• Download & Install Libraries API.
@ http://drupal.org/project/libraries
• Download lessphp @ http://leafo.net/lessphp/
and unpack it so that 'lessc.inc.php' is located at
'sites/all/libraries/lessphp/lessc.inc.php'.
• Download and install http://drupal.org/project/less.
26 of 16
27. www.drupalph.org
Changes should be made to theme
• Rename all [name].css file to [name].css.less
• Open and Edit [theme-name].info
-> Search and Replace “.css” to “.css.less” and save file.
• Open and Edit template.php
-> Search and Replace “.css” to “.css.less” and save file.
Make sure to check that .css files are loaded/imported using drupal_add_css()
api, otherwise don’t append .less unless you’ll change the loading/importing
using drupal_add_css().
27 of 16
28. www.drupalph.org
File placement during LESS compilation.
• If your source file was "sites/all/modules/test/test.css.less“
• Then your compiled file will be
"sites/[sites|default]/files/less/[random.string]/sites/all/modules/test/test.c
ss"
28 of 16
29. www.drupalph.org
Compatibility:
Fully compatible with "Optimize CSS files"
setting on "Admin->Site configuration->Performance"
(admin/settings/performance).
RTL (Right-To-Left Languages) support will work as long as your files are
named "somename.css.less".
Should work with most themes and caching mechanisms.
Confirmed to work with:
• Boost
• Advagg (Advanced CSS/JS Aggregation)
• Omega
29 of 16
30. www.drupalph.org
LINKS:
• Drupal = http://www.drupal.org/project/drupal
• Less Module = http://www.drupal.org/project/less
• Libraries Api Module = http://www.drupal.org/project/libraries
• LessPHP Library = http://leafo.net/lessphp/
• Less CSS Doc = http://lesscss.org/
30 of 16