Templates
Templates allow us to make pages with regular, reusable parts, render special, dynamic content, or mark pages with particular data structures.
#Format
Using a template on a page usually involves a string of text wrapped in a pair of curly brackets, like so:
{{TemplateName}}
Templates can have parameters, too, written like this:
{{TemplateName parameter1="v1" parameter2="v2"}}
If you add this to a page, rather than rendering the string as you wrote it, the Fifth World API will look for a template called TemplateName
. If the template exists, the API will render it (using v1
for parameter1
and v2
for parameter2
), and replace the string with the result of that rendering. If it doesn’t exist, the API will simply remove the string from the rendered page.
#Data templates
Since we simply remove the text if no template matches the invocation, we can use data templates to save information about a page, and then use the API’s GET /templates
endpoint to retrieve pages like that, or the special ListPagesUsingTemplate
template (see below) to render a list of them. If we decide later that we would like to render this data in some way, we can always add a template to do so.
For an example of this, see our entry on berries, which uses the Focus
template, along with parameters that specify that people gather berries in summer, and that both villages and bands sometimes dedicate themselves to gathering berries then. The community creation tool uses then uses this data to add berries to the list of foods that a community might focus on in the summer.
#System templates
The API has a small handful of built-in templates. These templates require some processing in the API to properly render, so you can’t create a template with any of these names, because then the renderer would have no way of distinguishing between your template and the built-in one.
#Art
This template allows you to render any art uploaded to the site as an image on a page.
Parameter | Notes |
---|---|
src | The path of the page for the art you want to use. |
numbered | If used (with any value), renders the art in a numbered figure (e.g., “Figure 1”). |
caption | Use this paramter to supply a caption for the art. |
useThumbnail | If used (with any value), renders the thumbnail rather than the full image. |
#Artists
This template finds all of the artists on the site (pages tagged with type "Artist"), lists them, and provides a small gallery of their four most recent works. We use it on the Art page.
#Children
This template creates a list of the page's child pages (or another page's children).
Parameter | Notes |
---|---|
of | Use this parameter to supply the path of a different page, to show that page's children instead of the current page's children. |
type | Use this parameter to limit the list to only children of the given type. |
order | Use this paramter to specify the order in which the renderer should list the children. You can choose between newest , oldest , and alphabetical . If you don't supply this parameter, it defaults to alphabetical order (by title). |
#Download
If you upload a file, you can use this template to render a link to download it.
Parameter | Notes |
---|---|
file | The path of the page for the file you want to provide a link to download. |