Thursday, May 27, 2010

Inserting CSS in HEAD with ModX

One of the neat things about ModX (or any CMS, really) is that you divide your HTML into chunks and reuse them across pages. Great as this is, it makes managing CSS a little annoying since you don't have any direct access to <head>.

Here's a quick snippet that solves that problem. Just insert [[register_css?file=`/assets/css/foo.css`]] in your template, page, or chunk, and create a snippet with this code:

if ($file) {
$modx->regClientCSS("<link rel='stylesheet' type='text/css' href='$file'></link>");
}
?>

No comments: