Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'm using Less in a project now and came across a situation where I needed to provide the path to a processed less file. It would be helpful for the module to provide something like this. Below is the helper function from my project. My guess is that you'd simply want to return the URI instead.
/**
* Helper function that returns the path of a processed Less file.
*
* @param $type The type of the item (i.e. theme, theme_engine, module, profile).
* @param $name The name of the item for which the path is requested.
* @param $path The path of the less file within your module or theme.
*
* @return Relative path to the resulting CSS file generated by Less.
*/
function less_get_path($type, $name, $path) {
// Work out the URI for the processed file.
$uri = file_default_scheme() . '://less/' . drupal_get_path($type, $name) . '/' . $path;
// file_create_url() turns a URI into a full URL. We want a relative URL so
// filter out the base URL.
$relative_path = str_replace($GLOBALS['base_url'], '', file_create_url($uri));
return $relative_path;
}
Comments
Comment #1
rickvug CreditAttribution: rickvug commentedI forgot that .less needs to be stripped off of the path provided:
Comment #2
corey.aufang CreditAttribution: corey.aufang commentedYou can do something like this to have less return the paths to compiled files. It will also compile the file if it doesn't exist yet.
Comment #3
corey.aufang CreditAttribution: corey.aufang commented