OK Sushi

MODx - Using Template Variables in the CSS

Posted on Tuesday June 20, 2006 in Work

This is a cool little trick I learned today.

Following on from this wicked technique – Selecting images per document – I ran into a problem.

In the past I had not used the MODx document structure to manage my CSS – but this technique required me to do so.

So I took out the CSS that I had to change from my source file and created a new document that I called ‘css’. I added the code I had just cut to this page and then saved it as file type ‘text/css’. I then added a reference to the file in the header of the template that was requiring the extra chunk of css, right after the existing call to the css file.

What I then had to do was work out how to use template variables in the CSS file. The CSS file could not use the existing template because the call to the file would include the template in the css, which just plain doesn’t work.

The solution is to create a new template called “BlankCSS” that only included the template variable content, in other words an empty template. Then tell your new template variable that you create using the technique linked to above to apply to the new template as well as your main template. Easy!

  1. Erm…. What? Can you try to explain a bit clearer with examples? Thanks.

    Posted by Ben on Oct 24, 09:17 AM
  2. An example would be greatly appreciated. Thanks for contributing to the community tho :) cheers
    Phil

    Posted by Phil on Mar 12, 05:19 PM

Comment on this article

Textile help

My flickr photos