[cvs] [Wiki] changed: Doc/Dev/TemplatePackage

Chuck Hagenbuch chuck at horde.org
Sun Oct 8 07:52:25 PDT 2006


chuck  Sun, 08 Oct 2006 07:52:25 -0700

Modified page: https://dev.horde.org/horde/wicked/Doc/Dev/TemplatePackage
New Revision:  1.5
Change log:  add toc, syntax updates

@@ -1,4 +1,6 @@
+[[toc]]
+
  These are just some basic examples on using Horde Templates... hopefully so others won't have to go picking the code apart to figure it out, some are obvious, some less so.
  
  The absolute minimum to get in the required functions for Horde_Template to work:
  
@@ -11,9 +13,9 @@
  (You're probably better off installing Horde's base.php or core.php, although it will load the whole Horde core, rather than just the templating engine, hence the above gives less of an overhead)
  
  Having set up the template object:
  <code type="php">
-  $template = &new Horde_Template();
+  $template = new Horde_Template();
  </code>
  
  If you want to fetch templates from a different base directory, then specify an argument to the "new" call with that base directory.
  
@@ -23,15 +25,13 @@
  
  <code type="php">
  echo $template->fetch($template_file);
  </code>
-
-If you don't do that, you'll not see any output, except maybe errors ;-)
  
  NB. If you make the PHP script do any output of its own, outside of the Horde_Template system, it will appear in the output positioned relative to the position of the above fetch() call in the code.
  
  
-+++ SIMPLE VARIABLES
++++ Simple Variables
  
  PHP:
  <code type="php">
  //In the php you have a variable like:
@@ -39,18 +39,17 @@
  //Set it into your template using:
      $template->set('foo', $foo);
  </code>
  
-TEMPLATE:
+Template:
  <code>
  <html><body>
    we have a foo value of <tag:foo />
  </body></html>
  </code>
  ** Note:** the <tag:... /> has to be exactly like above, with one space between the foo and />. Any other variation and the value will not be parsed. Unparsed tags  are left in the output in their original form, which shouldn't cause any visual distortion of the end result, as it's parsed by browsers as a HTML tag, but ignored because the browser doesn't know what it means.
  
-
-+++ ARRAYS
++++ Arrays
  
  PHP:
  <code type="php">
  //our php now builds an array to pass to the templates
@@ -58,9 +57,9 @@
  //and it is set into the template object
      $template->set('foo', $foo);
  </code>
  
-TEMPLATE:
+Template:
  <code>
  <html><body>
    we have many foo values:
    <loop:foo>
@@ -68,12 +67,11 @@
    </loop:foo>
  </body></html>
  </code>
  
-** Note:** use an loop construct to go through the foo tag and pull out all the values of foo. Again the syntax has to be precise or the tags will not get parsed.
+** Note:** use a loop construct to go through the foo tag and pull out all the values of foo. Again the syntax has to be precise or the tags will not be parsed.
  
-
-+++ ARRAY WITH KEYS
++++ Arrays With Keys
  
  PHP:
  <code type="php">
  //We now have an array with keys to pass
@@ -84,9 +82,9 @@
  //Again it is set the same way into the template object
      $template->set('foo', $foo);
  </code>
  
-TEMPLATE:
+Template:
  <code>
  <html><body>
    we have many foo values:
    <loop:foo>
@@ -94,28 +92,27 @@
    </loop:foo>
  </body></html>
  </code>
  
-** Note:** you need to have a loop array to parse through variables with keys. using the tags <tag:foo.somekey /> on their own without the loop tag will not work.
+** Note:** you need to have a loop array to parse through variables with keys. Using the tags <tag:foo.somekey /> on their own without the loop tag will not work.
  
-
-+++ IF CONDITIONS
++++ If Conditions
  
  PHP:
  <code type="php">
-//Set up the php variable, this checks if a user has been authorised
-//the checkUserAuth() function returning a true or false
+// Set up the php variable, this checks if a user has been authorised
+// the checkUserAuth() function returning a true or false
      $is_auth = checkUserAuth();
-//Set the 'if' variable into the template object, note the third parameter
-//which is being passed this time - it does nothing more than indicate to
-//the template parser that this is a variable for which an IF condition
-//will be checked. It has nothing to do with the actual value of the variable.
+// Set the 'if' variable into the template object, note the third parameter
+// which is being passed this time - it does nothing more than indicate to
+// the template parser that this is a variable for which an IF condition
+// will be checked. It has nothing to do with the actual value of the variable.
      $template->set('is_auth', $is_auth, true);
-//And we set up another variable for inclusion inside the if statement
+// And we set up another variable for inclusion inside the if statement
      $template->set('visitors', countvisits());
  </code>
  
-TEMPLATE:
+Template:
  <code>
  <html><body>
    welcome to our site...<br />
    <if:is_auth>
@@ -125,19 +122,18 @@
  </code>
  
  ** Note:** as always the syntax has to be precise, and the part within the <if:..></if:..> block will be shown only if $is_auth in the php sets the tag value of is_auth to true.
  
-
-+++ IF-ELSE CONDITIONS
++++ If-Else Conditions
  
  PHP:
  <code type="php">
      // the first true is the values set to the variable
      // the second true indicates it is going to be used in an if statement.
      $template->set('somename', true, true);
  </code>
  
-TEMPLATE:
+Template:
  <code>
  <html><body>
    welcome to our site...<br />
    <if:somename>
@@ -153,9 +149,9 @@
  
  ** Note:** the <else> statement must be enclosed in the <if> block.
  
  
-+++ IF CONDITIONS AND ARRAYS
++++ If Conditions and Arrays
  
  PHP:
  <code type="php">
      // the first true is the values set to the variable
@@ -163,9 +159,9 @@
      $users = array('john', 'peter', 'mary');
      $template->set('users', $users, true);
  </code>
  
-TEMPLATE:
+Template:
  <code>
  <html><body>
    welcome to our site...<br />
    <if:users>
@@ -185,9 +181,9 @@
  
  ** Note:** the <else> statement must be enclosed in the <if> block.
  
  
-+++ NESTED LOOPS AND NESTED TAGS
++++ Nested Loops and Nested Tags
  
  PHP:
  <code type="php">
  $categories = array('fruit', 'veggie', 'thing');
@@ -199,9 +195,9 @@
      $template->set('subcat_' . $c, $subcats[$c]);
  }
  </code>
  
-TEMPLATE:
+Template:
  <code>
  <table>
  <loop:categories>
  <tr>
@@ -218,9 +214,9 @@
  </loop:categories>
  </table>
  </code>
  
-OUTPUT:
+Output:
  I have a fruit. What could it be?
  * apple
  * pear
  
@@ -234,11 +230,9 @@
  * spoon
  * paperbag
  * tool
  
++++ Backward Compatibility
  
-+++ BACKWARD COMPATIBILITY
-
-It is possible to make Horde_Template backward compatible to some extent with other engines, eg. class.!FastTemplate.php by modifying the functions getTag
-and getTags with different tag patterns.
+It is possible to make Horde_Template backward compatible to some extent with other engines, eg. class.!FastTemplate.php by modifying the functions getTag and getTags with different tag patterns.
  
  This is left as an exercise for the reader.


More information about the cvs mailing list