Drupal
Drupal – Theming to keep your modules modular
3Drupal is a powerful CMS and allows us as developers to create very bespoke web sites and applications.
I tend to create a module for every website to handle its Page and Block declarations. But its messy and not to mention unconventional to include HTML in your modules. I want to share how to theme your page declarations and any other piece of HTML for that matter to keep your modules tidy.
(more…)
Drupal CSS aggregator
0
A couple of pointers when you’re getting into theming Drupal the correct way rather than just hacking around as is most fun.
I seem to hit troubles getting the aggregator feature of Drupal working, and often end up just slapping an external CSS link call in to the page template.
The proper way to do is a little long winded, but gives us the speed optimisations offered by the aggregator facility. Instead of putting <link … /> in the page.tpl.php file, use the drupal_add_css() function in your template.php file.
The best place to put it is in a function called <themename>_preprocess_page().
And here’s an example of what that function can contain…
function mytheme_preprocess_page(&$vars) {
//JA Inject theme styles and js
$resetcss = drupal_get_path('theme', 'mytheme') . '/yui/build/reset-fonts-grids/reset-fonts-grids.css';
$thickboxcss = 'misc/thickbox/thickbox.css';
$thickboxjs = 'misc/thickbox/thickbox-compressed.js';
drupal_add_css($resetcss, 'module', 'all', 1);
drupal_add_css($thickboxcss, 'theme', 'all', 1);
drupal_add_js($thickboxjs, 'theme', 'header');
$css = drupal_add_css();
$vars['styles'] = drupal_get_css($css);
$vars['scripts'] = drupal_get_js();
}
Some other things to watch out for .. make sure the path you provide the aggregator is relative from root but not relative to root… I’m not helping much am I!
I mean this …
misc/thickbox/thickbox.css
as oppossed to this …
/misc/thickbox/thickbox.css
Also make sure the web server has access to the files .. correct permissions etc.
I found that even pointing the aggregator at symlinks instead of the actual files was causing a problem .. probably to do with permissions on the real files.
Anyways .. hope that helps!
References:
http://api.drupal.org/api/function/drupal_get_css/6
http://api.drupal.org/api/function/drupal_add_js/6
