|
Cookbook /
CSSInWikiPagesSummary: Apply CSS styles via wiki pages
Status: Stable
Version: 2006-12-24
Prerequisites: pmwiki-2.0
Maintainer: DaveG
Download: stylepage.phpΔ
Discussion: CSSInWikiPages-Talk
QuestionCan I apply style sheet information to wiki pages on the fly by editing a wiki page? AnswerYes, there are three possible approaches: adding a markup rule; modifying the skin; or via the stylepage recipe. 1. MarkupThe easiest mechanism allows styles to be applied using wiki markup. Create a stylesheet (in, for example, Site.DefaultStyleSheet) that looks something like:
(:stylesheet:)
.class { ... }
element { ... }
(:stylesheetend:)
And add the following
Markup('stylesheet', '<[=',
"/\\(:stylesheet:\\)(.*?)\\(:stylesheetend:\\)/sei",
"\$GLOBALS['HTMLStylesFmt'][] = PSS('$1')");
The stylesheet will be applied to whichever page it is on, and can be included in other pages with a standard (:include Site.DefaultStyleSheet:) The stylesheet, or include directive, could be added to a GroupHeader page in order to have that style be applied to the whole group. If you want the stylesheet text to be invisible (e.g. if you're putting it on a GroupHeader page), mark it as a comment:
>>comment<<
(:stylesheet:)
.class { ... }
element { ... }
(:stylesheetend:)
>><<
2. SkinSometimes you might want the wiki to apply the sheet automatically without having to use You can apply styles to a page using the skin by putting something like the following in skin.php and typing css code into Site.StyleSheet:
global $pagename, $SiteGroup, $HTMLStylesFmt;
$pn = FmtPageName("$SiteGroup.StyleSheet", $pagename);
$page = ReadPage($pn, READPAGE_CURRENT);
if (!$page) { "The stylesheet page doesn't exist"; }
$stylesheettext = $page['text'];
$HTMLStylesFmt['skincss'] = $stylesheettext;
In any case, be careful with allowing CSS to be arbitrarily applied to a wiki page. Note that loading of style pages will add the css styles to the html page head, and if you specify a lot of styles it will slow down page loading, especially as the browser may need to reinterprete values already received via the normal skin's css file(s). The script below addresses this by having the style page written into a cached file. 3. The
|