Sometimes I need to refer to my generated CSS file but now that it is prefixed with microtime I cannot reliably know the path to the css file that is generated. For now I've created a small module to return the file for me, would you consider including something like this?

<?php 

/**
 * Implements hook_menu().
 */
function less_loader_menu() {
  $items = array();
  $items['lessloader/%'] = array(
    'title' => 'Less loader',
    'page callback' => 'less_loader_callback',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
  return $items;
}

/**
 * Callback.
 */
function less_loader_callback($type = 'global') {
  $args = func_get_args();
  array_shift($args);
  $path = '';
  
  if ($type == 'theme' || $type == 'module') {
    $name = array_shift($args);
    $path .= drupal_get_path($type, $name) . '/';
  }
  
  $path .= implode('/', $args);
  $less = _less_pre_render(array('#items' => array($path => array('data' => $path))));
  $less_file = file_create_url($less['#items'][$path]['data']);
  drupal_goto($less_file);
  exit;
}?>

I suppose most of the time it is not really necessary, but the reason I need this is my designer uses the generated stylesheets to mess around with static markup to add new components etc. It would also be a solution to #1474184: WYSIWYG does not load less styles although I think I prefer the solution in that issue better. There may be other modules etc that require the css file to be included (nice_menus is one off the top of my head).

Comments

corey.aufang’s picture

If you hook into the preprocess you should be able to retrieve the compiled path of the file easily.

The ['css'] array is keyed by the input file name so that should allow to find the path of the generated .css file.

corey.aufang’s picture

Status: Active » Closed (won't fix)