JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
rewrote template documentation
authorJason Woofenden <jason@jasonwoof.com>
Sun, 24 Oct 2010 01:14:38 +0000 (21:14 -0400)
committerJason Woofenden <jason@jasonwoof.com>
Sun, 24 Oct 2010 03:13:09 +0000 (23:13 -0400)
doc/template.php.txt
examples/404.html
examples/calendar.html
test/session_test.html
test/tem_test.php.html
uploader/uploader.html

index 416b6ac..53186f9 100644 (file)
@@ -1,39 +1,36 @@
-       First you have some globally accessible array of key->value pairs which contain the data to be entered into templates
+First, create a template object:
 
-       Then you have some template files
+       $tem = new Tem();
 
-tem_set($key, $value)
-tem_get($key)
-tem_run($file/template)
-tem_echo($file/template) { echo tem_run($file); }
+Then, load a template file (note: this can be done after you put the values in)
 
-This should work for simple templates such as:  foo: '~foo~'
+       $tem->load('template.html');
+       # or
+       $tem->load_str("""
+       <head><title>~title html~</title></head>
+       <body><table>
+               <th>Letter</th><th>Is For</th>
+               <!--~alphabet_table {~-->
+                       <td>~letter html~</td><td>~is_for html~</td>
+               <!--~end~-->
+       </table></body></html>""");
 
+Then give it some data:
 
-       It gets trickier when you have bits in your template that need to be repeated
-       (with different tags each time) and others perhaps not displayed at all.
+       $tem->set('title', 'Example Template Output');
+       $tem->set('alphabet_table', array(
+               array('letter' => 'A', 'is_for' => '<A>pple'),
+               array('letter' => 'B', 'is_for' => '<B>anana')));
 
-       foobar.html:
+Then you can get/print the output:
 
-<table>
-<tr><th>foo</th><th>bar</th></tr>
-<!--~foobar_row {~--><tr><td>~foo~</td><td><input value="~bar~"></tr><!--~}~-->
-</table>
+       echo $tem->run();
 
-tem_load('foobar.html');
+And you should see this:
 
-               
-               the main template (with the sub-templates like foobar_row replaced with a single tag ie:
-
-<table>
-<tr><th>foo</th><th>bar</th></tr>
-~foobar_row~
-</table>
-
-       Main data structure:
-               key/value pairs
-               template file (if template string is empty, it will be read from here)
-               template string
-               sub templates:
-                       key: foobar_row
-                       value: <tr><td>~foo.....html~</td><td><input value="~bar.attr~"></tr>
+       <head><title>Example Template Output</title></head>
+       <body><table>
+               <th>Letter</th><th>Is For</th>
+                       <td>A</td><td>&gt;A&lt;pple</td>
+                       <td>B</td><td>&gt;B&lt;anana</td>
+       </table></body></html>
index 2802848..e2c1c1d 100644 (file)
@@ -8,6 +8,6 @@
 <body>
 <h1>404 File Not Found</h1>
 
-<p>Sorry, ~filename.html~ doesn't seem to exist.</p>
+<p>Sorry, ~filename html~ doesn't seem to exist.</p>
 </body>
 </html>
index 8edc126..ab6077f 100644 (file)
@@ -10,7 +10,7 @@
   <div class="calendar">
     <table border="0" cellspacing="0" cellpadding="0" summary="">
       <tr>
-        <td colspan="7" class="year">~month_year.html~</td>
+        <td colspan="7" class="year">~month_year html~</td>
       </tr>
       <tr>
         <th><div class="headerbox">Sun</div></th>
         <th><div class="headerbox">Fri</div></th>
         <th><div class="headerbox">Sat</div></th>
       </tr>
-      <!--~week start~-->
-      <tr><!--~day start~--><!--~nonday start~-->
-        <td class="nonday"><div class="daybox">&nbsp;</div></td><!--~end~--><!--~empty_day start~-->
-        <td class="empty_day"><div class="daybox">~day_number.html~</div></td><!--~end~--><!--~busy_day start~-->
-        <td class="busy_day"><a href="~day_page.attr~">~day_number.html~</a></td><!--~end~--><!--~empty_weekend start~-->
-        <td class="empty_weekend"><div class="daybox">~day_number.html~</div></td><!--~end~--><!--~busy_weekend start~-->
-        <td class="busy_weekend"><a href="~day_page.attr~">~day_number.html~</a></td><!--~end~--><!--~end~-->
+      <!--~week {~-->
+      <tr><!--~day {~--><!--~nonday {~-->
+        <td class="nonday"><div class="daybox">&nbsp;</div></td><!--~}~--><!--~empty_day {~-->
+        <td class="empty_day"><div class="daybox">~day_number html~</div></td><!--~}~--><!--~busy_day {~-->
+        <td class="busy_day"><a href="~day_page attr~">~day_number html~</a></td><!--~}~--><!--~empty_weekend {~-->
+        <td class="empty_weekend"><div class="daybox">~day_number html~</div></td><!--~}~--><!--~busy_weekend {~-->
+        <td class="busy_weekend"><a href="~day_page attr~">~day_number html~</a></td><!--~}~--><!--~}~-->
       </tr>
-      <!--~end~-->
+      <!--~}~-->
     </table>
   </div>
 </body>
index aa3749e..684d788 100644 (file)
@@ -9,25 +9,25 @@
 
 <h1>testing code/wfpl/session.php</h1>
 
-<!--~block start~-->
+<!--~block {~-->
 <div style="border: 2px solid black; padding: 10px; margin-top: -2px">
-  <h2>~message.html~</h2>
+  <h2>~message html~</h2>
   
   <p>
   <table cellpadding="5" cellspacing="0" border="1" summary="">
     <tr><td colspan="4" style="font-weight: bold">wfpl_sessions table</td></tr>
-    <tr><td>id</td><td>session_key</td><td>length</td><td>expires</td></tr><!--~wfpl_sessions_row start~-->
-    <tr><td>~id.html~</td><td>~session_key.html~</td><td>~length.html~</td><td>~expires.html~</td></tr><!--~end~-->
+    <tr><td>id</td><td>session_key</td><td>length</td><td>expires</td></tr><!--~wfpl_sessions_row {~-->
+    <tr><td>~id html~</td><td>~session_key html~</td><td>~length html~</td><td>~expires html~</td></tr><!--~}~-->
   </table>
   </p>
   <p>
   <table cellpadding="5" cellspacing="0" border="1" summary="">
     <tr><td colspan="4" style="font-weight: bold">wfpl_session_data table</td></tr>
-    <tr><td>id</td><td>session_id</td><td>name</td><td>value</td></tr><!--~wfpl_session_data_row start~-->
-    <tr><td>~id.html~</td><td>~session_id.html~</td><td>~name.html~</td><td>~value.html~</td></tr><!--~end~-->
+    <tr><td>id</td><td>session_id</td><td>name</td><td>value</td></tr><!--~wfpl_session_data_row {~-->
+    <tr><td>~id html~</td><td>~session_id html~</td><td>~name html~</td><td>~value html~</td></tr><!--~}~-->
   </table>
   </p>
 </div>
-<!--~end~-->
+<!--~}~-->
 </body>
 </html>
index 385cecb..37ebdea 100644 (file)
@@ -15,7 +15,7 @@ special things: sub-templates and template tags. -->
   sub-template. It marks a section of template which the php can decide how
   many times to display (including none.) -->
   
-  <!--~login start~-->
+  <!--~login {~-->
   <h3>Please Log In Below</h3>
 
   <form method="get" action="tem_test.php">
@@ -32,7 +32,7 @@ special things: sub-templates and template tags. -->
                putting it in a text file or e-mail then leave the encoding off and
                just put ~user~. -->
 
-        <td><input type="text" name="user" value="~user.attr~"></td>
+        <td><input type="text" name="user" value="~user attr~"></td>
       </tr>
 
       <tr>
@@ -40,7 +40,7 @@ special things: sub-templates and template tags. -->
 
         <!-- there's another template tag named pass -->
 
-        <td><input type="password" name="pass" value="~pass.attr~"></td>
+        <td><input type="password" name="pass" value="~pass attr~"></td>
       </tr>
 
       <tr>
@@ -51,14 +51,14 @@ special things: sub-templates and template tags. -->
 
   <!-- and here's the mark for the end of the login sub-template. -->
 
-  <!--~end~-->
+  <!--~}~-->
 
 
   <!-- Now for a more complex example of sub-templates. This whole table is in
   a sub-template so php can decide to display the whole bit or not. First the
   marker for the begining of the sub-template -->
 
-  <!--~foobar_table start~-->
+  <!--~foobar_table {~-->
   <h3>All your foobar:</h3>
 
   <table summary="">
@@ -72,16 +72,16 @@ special things: sub-templates and template tags. -->
        in this table, so we make a template with just one row, and mark that row
        as a sub-template named foobar_row -->
     
-    <!--~foobar_row start~-->
+    <!--~foobar_row {~-->
     <tr>
          <!-- sorry that the following tag looks a bit like a filename. It isn't.
          It's simply asking PHP for a value called "foo" encoded as html -->
-      <td>~foo.html~</td>
+      <td>~foo html~</td>
 
-      <td><input value="~bar.attr~"></td>
+      <td><input value="~bar attr~"></td>
     </tr>
     <!-- Here's the end of foobar_row -->
-    <!--~end~-->
+    <!--~}~-->
 
     <tr>
       <td></td>
@@ -91,6 +91,6 @@ special things: sub-templates and template tags. -->
 
   </table>
   <!-- and the end of foobar_table -->
-  <!--~end~-->
+  <!--~}~-->
 </body>
 </html>
index 3f0e610..9c713ef 100644 (file)
@@ -6,7 +6,7 @@
 </head>
 
 <body>
-<!--~main start~-->
+<!--~main {~-->
   <div id="wfpl_progress_form">
     <form action="http://~host~:~port~/~filename~" enctype="multipart/form-data" target="wfpl_progress_post_response" method="post">
       <p>Upload a file: <input type="file" name="wfpl_uploader_file" id="wfpl_uploader_file"></p>
@@ -24,6 +24,6 @@
       <div id="wfpl_progress_bar"></div>
     </div>
   </div>
-<!--~end~-->
+<!--~}~-->
 </body>
 </html>