guard templates with the if directive where necessary
authorhttp://jmtd.livejournal.com/ <http://jmtd.livejournal.com/@web>
Mon, 15 Nov 2010 14:28:05 +0000 (14:28 +0000)
committerJoey Hess <joey@kitenet.net>
Mon, 15 Nov 2010 14:28:05 +0000 (14:28 +0000)
doc/ikiwiki/directive/template.mdwn

index 9e3ae54dfd6209c92528ace49ad5ae2b3279d486..df391f99e0a23dd7cda85a8c29c1aef80baa707f 100644 (file)
@@ -60,22 +60,30 @@ few things:
   `<TMPL_IF variable>text</TMPL_IF>`.
 * To use one block of text if a variable is set and a second if it's not,
   use `<TMPL_IF variable>text<TMPL_ELSE>other text</TMPL_IF>`
+* Each template file included in the wiki's source will also generate a regular
+  wiki page.  In many cases you might want to prevent some of your template
+  being interpreted for the regular page.  Use the [[if]] directive with the
+  `included()` test to guard the template code.
 
 Here's a sample template:
 
-        <span class="infobox">
-        Name: \[[<TMPL_VAR raw_name>]]<br />
-        Age: <TMPL_VAR age><br />
-        <TMPL_IF color>
-        Favorite color: <TMPL_VAR color><br />
-        <TMPL_ELSE>
-        No favorite color.<br />
-        </TMPL_IF>
-        <TMPL_IF notes>
-        <hr />
-        <TMPL_VAR notes>
-        </TMPL_IF>
-        </span>
+        \[[!if test="included()" then="""
+          <span class="infobox">
+          Name: \[[<TMPL_VAR raw_name>]]<br />
+          Age: <TMPL_VAR age><br />
+          <TMPL_IF color>
+            Favorite color: <TMPL_VAR color><br />
+          <TMPL_ELSE>
+            No favorite color.<br />
+          </TMPL_IF>
+          <TMPL_IF notes>
+            <hr />
+            <TMPL_VAR notes>
+          </TMPL_IF>
+          </span>
+        """ else="""
+          This is a template page.
+        """]]
 
 The filled out template will be formatted the same as the rest of the page
 that contains it, so you can include WikiLinks and all other forms of wiki