Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

FillTemplate

Summary: Combines a template page with a data page to present PmWiki content
Version: 1.0rc - initial release
Prerequisites: PmWiki 2.1
Status: RC
Maintainer: Octocias
Categories: Layout

Questions answered by this recipe

  • I have many pages of a category and would like to present them using a layout template in such a way that in future, changing the template automatically updates every page using it.

Usage

(:FillTemplate <template page> <template section> <data source>:)

Installing

Download oct-filltemplate.phpΔ and copy it to your cookbook folder. Install by adding to config.php:

include_once("$FarmD/cookbook/oct-filltemplate.php");

Description

Custom markup (:FillTemplate:) combines layout information from a template page with content from a data page in order to showcase PmWiki content in optional and predefined forms.

The template page contains any number of sections (stored between PmWiki bookmarks). Each 'section' represents an optional 'view' of the data. For example, a template page might contain sections:

  • RowData - used when showing a summary of members of a collection
  • Thumbnail - used when only wanting a thumbnail complete with link to a destination
  • FullPage - used to display all possible detail for a particular member of the collection.

Template data substitute live content with keywords. Keywords are used in the format (_KEYWORD_). e.g. (_FirstName_), (_LastName_), etc.

When the template is being filled, the markup simply replaces (for instance) (_FirstName_) in the template with the data found in the provided Data Page between [[#FirstName]] and [[#FirstNameEnd]].

To see it in action, visit my 'Relationships/Friends' page at http://www.octocias.com.

Markup arguments:

  • <template page>
    • A path to the WikiPage that contains templated layout data for one or more sections. The template page stores layouts in sections which replace actual content with keywords.
  • <template section>
    • A name that refers to the subsection of a template page. For example, it could be 'RowData' (without quotes). A section of that name should of course exist in the template page using the format:
      [[#SectionName]] (section content goes here) [[#SectionNameEnd]]
  • <data source>
    • A path to the WikiPage that contains the data to replace template KEYWORDS.

Step by step tutorial

I'll walk you through creating a gallery for people, similar to what I have on my personal website (see above for the url). Substitute the GROUP and PAGE names according to your site setup.

1. Create a data source

Create a page called Main.AlexData (e.g.Main.AlexData?action=edit)

Inside it place the following text:

[[#WebDir]]UrlToData:friends/alex[[#WebDirEnd]]
[[#FirstName]]Alex[[#FirstNameEnd]]
[[#LastName]]Prykhodko[[#LastNameEnd]]
[[#SummaryText]]This is customised summary text for (_FirstName_) of the (_LastName_) variety ;)[[#SummaryTextEnd]]
[[#ThumbTarget]]http://[[#ThumbTargetEnd]]
[[#ThumbImg]](_WebDir_)/thumbnail.png[[#ThumbImgEnd]]

Repeat this for other people as you desire.

2. Create a template

Create a page called Main.FriendsTemplate (e.g.Main.FriendsTemplate?action=edit)

Note: This page is never viewd directly, so what you type outside the bookmarks does not matter.

Inside it, type:

[[#TableRow]]
(:cellnr width=5% :)
%newwin%[[(_ThumbImg_) -> (_ThumbTarget_)]]
(:cell style='padding:3px; border-top: #2F6FA2 solid 1px;' bgcolor=#fcfafc:)
'+'''(_FirstName_) (_LastName_)'''+'[[<<]]
(_SummaryText_)
[[#TableRowEnd]]

3. Finally, create a display page

This is the page which will showcase your data, using the templates to apply the predefined layout.

Create a page called Main.Friends (e.g.Main.Friends?action=edit)

Inside it, place the following:

! My friends
(:table width='90%' align=center:)
(:FillTemplate Main.FriendsTemplate TableRow Main.AlexData:)
(:FillTemplate Main.FriendsTemplate TableRow Main.MarcData:)
   .
   .
   .
(:tableend:)

That's it. You should be able to use this information to make it do far more for you.

Notes

Release Notes

  • 2006.04.11 - 1.0rc: first released into the wild.

Comments

Congratulations! Very nice recipe and documentation. It looks like it has alot of potential.

  • Reading through the tutorial I see that the display page is hardcoded with references to each data page (and template). I wonder whether that part of the process could be automated as well using pagelist, or similar methods, which would use a single line of markup with a wildcard reference to the data pages to generate the line by line reference that your display page requires.
    • The fact that pagelist results can't be used to drive wikitrails indicates that this might not work without some recoding, which you seem up to the task of; but if you can find a way to get your code to accept markup generated by PageLists and PageListTemplates, that would seem like a much better route.
  • While your tutorial uses examples where all files exist under the same group, called "Main," if users organize pages under different groups, for example, placing data and templates in separate group(s) from display pages, then the data group could be used to simplify the wildcard search, and the data (and templates) could be locked down to prevent visitors from wandering into and editing these pages.
  • Once you start down this path of using pagelist to drive the display page, you could use the same method to allow a searchbox to drive the display, allowing users to use searches to generate their own display pages (which would be great for a knowledge base wiki, for example).
  • Anyway, great work, and thanks for sharing your work. Pico April 11, 2006, at 08:08 AM

See Also

You may want to take a look at the Clipboard. It does template filling too (to get a field use (:paste clip id=FirstName:) ).

Contributors

Edit - History - Print - Recent Changes - Search
Page last modified on April 29, 2006, at 04:58 PM