MindTouch Developer Center > Deki > FAQ > Page Management > How do I...Create and insert a parameterized template?

How do I...Create and insert a parameterized template?

Table of contents
No headers

A template is a page that can be inserted into another page.  Templates provide a convenient mechanism for setting up boilerplate content on your wiki.  This tutorial focuses on how to create a template that can be adjusted later on so that existing pages reflect the changes:

1.  Select Tools->Templates.

./Image1.JPG
Figure 1

2.  Click the New Page button to open a new template in the editor.

3.  Enter the template name and content.   The following example creates a template titled "FAQ Entry".  It expects two parameters "question" and "answer" and accesses their values using {{ $question }} and {{ $answer }}:

./Image2.JPG
Figure 2

4.  To use the template, open the destination page and enter:

{{ wiki.template( "<name>", {<arg1>: <value1>, <arg2>: value2, ... }) }}

Where <name> is the name of the template, <arg1> is the name of the first parameter, <value1> is the value of the first parameter, and so on.  For example, the following page includes the "FAQ Entry" template with the "question" and "answer" parameters:

./Image3.JPG Editor View ./Image4.JPGAfter Save


If the appearance of the "FAQ Entry" template changes, it will automatically be reflected on this page.

Tag page
Viewing 3 of 3 comments: view all
Would it be possible to use this with the Wiki.Create function aswell? It would be really useful to be able to create automated pages using a specific template and passing parameters to the template during creation.
Posted 12:17, 11 Aug 2008
Yes, you can. In order for the parameters to be substituted at edit time, you must prefix your dekiscript code with "edit:". For example: {{edit: date.now}} or {{edit: __request.args.parameter_name}}
Posted 14:04, 11 Aug 2008
Ah, that worked perfectly. I was almost there, but I was trying with "save:", which of course wouldn't work. =)
Posted 04:22, 12 Aug 2008
Viewing 3 of 3 comments: view all
You must login to post a comment.
Powered by MindTouch Deki v.8.08.2