I am trying to create a custom module that programmatically creates a LESS file.
I created a menu callback that is a file. Here is hook_menu()...
$items['sites/all/themes/universal/less/dynamic.css.less'] = array(
'page callback' => 'jobs_universal_lessvars',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK
);
Here is the callback.
function jobs_universal_lessvars(){
header('Content-type: text/css');
$output = '
@color: #4D926F;
body.notaclass {
color:@color;
}
';
print $output;
}
And I call this to add it.
function universal_preprocess_html(&$variables) {
drupal_add_css(drupal_get_path('theme','universal').'/less/dynamic.css.less');
}
I uploaded a static file to the above ^^ path, disabled the menu callback, and it processed/applied correctly. When I try to run this module, it's not included and I get an error saying
LESS error: load error: failed to find sites/all/themes/universal/less/dynamic.css.less
Before you answer...
- I have the LESS module installed
- I have the LESS library uploaded correctly
- I have tested that I can include a static .less file and have it process
- I have tested the menu callback by manually going to the URL
- I have tried it with and without calling header('Content-type: text/css');
I get it... it's not a file. But it "is", right? I could just call this function and have it create a new CSS file that's added, but it doesn't fulfil the requirements of the module. Help me? :) Programmatically creating files is very new to me!
drupal_add_css(DRUPAL_ROOT . drupal_get_path('theme', 'universal') . '/less/dynamic.css.less');
. I'm confused why you need to do this if you already have the LESS module installed; what are you achieving with this ? – tenken Dec 19 '13 at 22:54