Textpattern plugin : ajw_custom_css

15 January 2005 @ late morning | Comments (1)

Plugin Details

Download:
ajw_custom_css
Version:
0.4
Forum:
Read discussion
Status on this site:
Disabled

Please use forum for all bug reports and questions

Summary

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) to store a value flagging an article as requiring 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.

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.

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.

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

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

Revision History

  • v0.4
    • Fixed regex
  • v0.3
    • Cleaned up php error notices
  • v0.2
    • Add support for ‘title’ attribute
    • Add support for ‘media’ attribute

1 comment

1

Good job! It works nicely, in my tests on localhost.

Additionally, you can add attributes such as media=”screen,projection” and title=”my stylesheet title” without problems.

Thanks again.
Philippe

Philippe → emps.l-c-n.com

Comments are closed for this article.

Previously

Elsewhere