Content last modified Tuesday 24 August 2021
hop to #bottom
Categories:
Author:
Current version:
0.2
About It:
Get it:
Rate it:
  • Helpful?
  • 0 Yes
  • 0 No
Flag it:

If you'd like to provide updated information and do not have access to directly edit, please contact the site admin; thanks!

ajw_custom_css

Disclaimer: Ideally, this should/could be accomplished with Mark Norton’s mdn_if_custom plugin. But because that plugin is designed for use within articles and depends on variables that do not yet exist at the time non-article forms are parsed in Textpattern ($thisarticle & $pretext), this separate plugin was written and successfully sidesteps that issue.

Allows for conditional stylesheets on a per-article basis. Inspired by Khoi Vinh at Subtraction

There are three small, non-hack prerequisites for this to function:

  • You must have a custom field available (defined in textpattern/lib/admin_config.php) in order to store the ‘true’ (or any non-empty) value, signaling that an article is using custom CSS.
  • You must name the CSS file according to the article ID number. For instance, article 63 would use ‘63.css’.
  • You must store all the CSS files in the same location.

Attributes

field
Number corresponding to the custom field you’re using. Any value whatsoever stored inside that custom field for an article will be seen as a boolean TRUE value. I just use a custom field named ‘CSS’ and type ‘1’ if the article uses custom CSS.
path
OPTIONAL. A value such as ‘/css’ or ‘/assets/css’ (requires leading slash). If no path, default is relative to document root.
usehtml
OPTIONAL. By default, the stylesheet link tag will be output in XHTML format. By setting this value to ‘1’ you may opt for HTML.
media
OPTIONAL. Allows for media types such as screen, projection, print, etc.
title
OPTIONAL. Allows for assigning a title to the stylesheet.

Examples

This plugin is designed to be used within your main page template (or whichever form you use that contains the document <head>). Just simply put in the plugin tag after your normal style link tags and it will output article-specific link tags if the corresponding custom field has a value stored in it.

<txp:ajw_custom_css field="1" path="/css" />
<link rel="stylesheet" type="text/css" href="/css/63.css" />

<txp:ajw_custom_css field="1" nohtml="1" />
<link rel="stylesheet" type="text/css" href="/63.css" >

Changes in version 0.2

  • Add support for ‘title’ attribute
  • Add support for ‘media’ attribute
Article Request Count:
Initially released:
15 January 2005
Posted here:
11 Apr 2005

You know you want to visit the Archives.
Published with Textpattern