Less Variables and Hooks

Last updated on
30 April 2025

You are browsing documentation for an older version of Drupal, which is not supported any longer, and the information may not be correct. See current documentation for Contributed modules

Variable and Hook documentation for the Less CSS Preprocessor module.

The following only applies to Less 7.x-4.x+ release series.

The Less module provides 3 sets of hooks (variables, paths, functions), and the alter variations.

Less hook implementations can and should be placed in a MODULE.less.inc file, where MODULE is the system name of the implementing module/theme.

Full hook documentation can be read in less.api.php within the Less module directory.

Using Less hooks in theme's template.php

You can only use the '_alter' hooks from within your theme's template.php. This is a limit imposed by Drupal core.

Additionally, you will only see the effect when it is the current theme: http://drupal.stackexchange.com/a/131200/17140

Any Less variable defaults should be declared from within the .info file as you will not see the value on the theme configuration page otherwise.

Variables

Variable defaults can be defined in .info files for modules or themes. Any variables defined will be automatically available inside style sheets associated with the module/theme.

Variables UI:

Any variables that are defined in the .info file or with hook_less_variables() are available to edit in the theme settings page.

Defining variable defaults:

.info file:

less[vars][@varname] = #bada55

hook_less_variables() in PHP:

function hook_less_variables() {
  return array(
    '@variable_name_1' => '#ccc',
    '@variable_name_2' => 'darken(@variable_name_1, 30%)',
  );
}

Variables that are defined in the .info file or in hook_less_variables() will be available in Less sheets that are associated with that module/theme.

Less sheets that are added through stylesheets[all][] in the .info file are automatically associated with the module/theme as well as automatically included on any page.

If you wish to associate a Less sheet with a module, and its supplied variables, without automatically including it on every page, you can use this notation in your .info file:

less[sheets][] = relative/path/to/stylesheet.css.less

There are more detailed examples of the hooks provided by Less in the less.api.php file included with the Less module, as well as the bundled less_demo module.

Functions

Deprecation:

Less function hooks are most likely going to be deprecated soon as the new suggested library (oyejorge/less.php) for pure PHP compiling does not support them.

Documentation for current Less function hooks can be found in the less.api.php file and the less_demo module, both packaged within the Less module.

Help improve this page

Page status: Not set

You can: