You are here: Wiki » Technical » Templates

Templates

The templatery plugin offers the ability to write a template, and have it included in other pages with filled in fields.

Example

The anatomy of a template

Defining a template is very simple:

<template example>

This starts a new template. The template can optionally have a name ('example' in this case).

Hello, my name is: @@name@@

A piece of text with a field called 'name'.

<if organisation>
I'm a member of @@organisation@@.
</if>

A conditional piece of text. If the field 'organisation' is present, this will be displayed. If the field is not defined, the whole piece won't be used.

</template>

Finishes the template.

The actual template

The template will end up looking like this:

example

Hello, my name is: name

With organisation

I'm a member of organisation.

Using the template

You use the template with

{{template>tech:templates#example|name=Brend|organisation=University of Twente}}

This tells the wiki to use the template tech:templates#example.

If you do not have a full name, but something like {{template>test}} the wiki will look in the Template namespace for the template.

Looks like this

Hello, my name is: Brend

I'm a member of University of Twente.

Using parameters

A template can have both named and numbered parameters.

Numbered parameters

Parameters can be numbered:

numbered

0 = 0, 1 = 1

0 = Alpha , 1 = beta

You can freely mix numbered and named parameters.

Default values

Parameters can be given a default value:

defaults

a » Default value for a & b » Default value for b

Alpha & Default value for b

Conditionals

You can have conditional pieces of template:

conditionals
With a

Text if a is set. a = a

Without a

Text if a is not set. a = a

With A set

Text if a is set. a = Alpha

With A unset

Text if a is not set. a =

Inline Conditionals

You can use inline conditionals for inclusion in places where normal conditionals don't work (such as in lists, tables, etc.) The system will try to determine when to use an inline conditional by itself. You can force an inline conditional with *.

inline_conditionals1
  • The trick: With aText if a is set. a = a

Forced inlines conditionals can be used With ainside of paragraphs!

With A

  • The trick: Text if a is set. a = Alpha

Forced inlines conditionals can be used inside of paragraphs!

Templates in Templates

You can include a template in a template. This allows you to reuse templates.

If you dot this, you use {{template>name of template|inside=outside}}. The variables assignments are used to remap variables from outside the template to inside the template. Any variable not mentioned is available under it's old name.

recursion

0 = 0

With 1

tech:templates#recursion : 1 → 0, 2 → 1, 3 → 2, 4 → 3

0 = Alpha

0 = Beta

0 = Gamma

0 = Delta

Data and Templates

Combining templates and data is a good way to display a lot of data while still keeping it readable.

We can combine the data and the template with a 'view':

<view ?name ?knows>
template {
  manuals:stratatemplatery
}

?p is a: example_person
?p entry title: ?name
?p Knows [ref]: ?knows

group {
  ?p
  ?name
}
</view>

The <view> works exactly like Strata: Structured Data Plugin, with the addition of the template group.

Template with types

You can use types and aggregations in fields in the template. For example rating@max [dot] will determine the maximum value of the 'rating' field in the query, and display this with the 'dot' type.

Typed Templates

You can use types in vanilla templates as well. This allows you to display nicer templates without extra effort.

typed

An example: a With explicit type: b [ref]

When filled in with a[wiki]=5 (:food) + 7 (:healthcare) and b=ic:Nehket Aeka this gives the following:

An example: 5 + 7 With explicit type: Nehket Aeka

 
tech/templates.txt · Last modified: 2013/12/28 01:29 by Brend
|
Recent changes RSS feed Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki