PmWiki: LayoutBasics

This page is being updated to reflect the new layout scheme used in pmwiki versions 0.6.1 and later. Versions of PmWiki prior to 0.6.0 may want to look here [http://www.pmwiki.org/wiki/PmWiki/CustomHeadersAndFooters5].

This page describes how a WikiAdministrator can customize the layout (headers and footers) that appear on PmWiki pages. As of PmWiki 0.6.1, the layout is usually controlled by a "template file" stored in the pub/skins/ directory. PmWiki is distributed with a default "pmwiki" skin template file in pub/skins/pmwiki/pmwiki.tmpl. To customize the layout, you simply create a new template file and then add a line such as

        $PageTemplateFmt = "pub/skins/myskin/myskin.tmpl";

to your local/config.php file.

See Cookbook:Skins for template files and layout designs that others have contributed.

Creating or modifying a template

To customize a layout, you can either create a new template file from scratch, or you can modify an existing template file. If you want to use one of the files that came with PmWiki as your starting point, you should make a copy of the file and work from the copy instead of editing the original, or your modifications may be lost when upgrading PmWiki. Don't forget to set the value of $PageTemplateFmt to point to your new template file in local/config.php.

A template file is basically an HTML file that also contains variable substitutions (indicated by '$') and special directives embedded in HTML comments. Two of these special directives are required in the template file. The directive <!--PageText--> belongs to the <body> section of the HTML document, and tells PmWiki where the main content of each wiki page should be placed. The other required directive is <!--HeaderText-->, which goes somewhere in the <head> section of the HTML document.

Throughout the layout template, variables such as $PageUrl, $ScriptUrl, $Group, and $Title are replaced with the URL of the current page, the base URL to the pmwiki.php script, the name of the current WikiGroup, and the title of the page being displayed. Other variables in the template are substituted with the values of the equivalent PHP global variables. Some other common sequences:

    $Titlespaced -  the title of the page with spaces between words
    $Groupspaced -  the group of the page with spaces between words

Finally, the template can contain other directives to output the contents of other pages, files on disk, or to call other PHP functions. The directive <!--wiki:Main.SomePage--> can be used to display the contents of Main.SomePage at some point within the layout. This is useful to create editable menus or sidebars from pages other than the one currently being displayed. Variable substitutions work here, so <!--wiki:$Group.SomePage--> will display the contents of "SomePage" in the current WikiGroup. Multiple alternatives can also be specified, thus <!--wiki:$Group.SomePage Main.SomePage--> displays the contents of SomePage in the current group, and if that page doesn't exist then Main.SomePage is used instead.

<< LocalCustomizations | PmWiki.DocumentationIndex | LayoutAdvanced >>
本頁更新於 2004 年 04 月 03 日,11:54 PM