From 46b55cc36d0767571ec0ae49e243ecc3bf7d127f Mon Sep 17 00:00:00 2001 From: Jason Woofenden Date: Sat, 23 Oct 2010 21:14:38 -0400 Subject: [PATCH] rewrote template documentation --- doc/template.php.txt | 57 +++++++++++++++++++++++------------------------- examples/404.html | 2 +- examples/calendar.html | 18 +++++++-------- test/session_test.html | 14 ++++++------ test/tem_test.php.html | 20 ++++++++--------- uploader/uploader.html | 4 ++-- 6 files changed, 56 insertions(+), 59 deletions(-) diff --git a/doc/template.php.txt b/doc/template.php.txt index 416b6ac..53186f9 100644 --- a/doc/template.php.txt +++ b/doc/template.php.txt @@ -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(""" + ~title html~ + + + + + +
LetterIs For~letter html~~is_for 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' => 'pple'), + array('letter' => 'B', 'is_for' => 'anana'))); - foobar.html: +Then you can get/print the output: - - - -
foobar
~foo~
+ 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: - - - -~foobar_row~ -
foobar
- - 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: ~foo.....html~ + Example Template Output + + + + +
LetterIs ForA>A<ppleB>B<anana
diff --git a/examples/404.html b/examples/404.html index 2802848..e2c1c1d 100644 --- a/examples/404.html +++ b/examples/404.html @@ -8,6 +8,6 @@

404 File Not Found

-

Sorry, ~filename.html~ doesn't seem to exist.

+

Sorry, ~filename html~ doesn't seem to exist.

diff --git a/examples/calendar.html b/examples/calendar.html index 8edc126..ab6077f 100644 --- a/examples/calendar.html +++ b/examples/calendar.html @@ -10,7 +10,7 @@
- + @@ -21,15 +21,15 @@ - - - - - - - + + + + + + + - +
~month_year.html~~month_year html~
Sun
Fri
Sat
 
~day_number.html~
~day_number.html~
~day_number.html~
~day_number.html~
 
~day_number html~
~day_number html~
~day_number html~
~day_number html~
diff --git a/test/session_test.html b/test/session_test.html index aa3749e..684d788 100644 --- a/test/session_test.html +++ b/test/session_test.html @@ -9,25 +9,25 @@

testing code/wfpl/session.php

- +
-

~message.html~

+

~message html~

- - + +
wfpl_sessions table
idsession_keylengthexpires
~id.html~~session_key.html~~length.html~~expires.html~
idsession_keylengthexpires
~id html~~session_key html~~length html~~expires html~

- - + +
wfpl_session_data table
idsession_idnamevalue
~id.html~~session_id.html~~name.html~~value.html~
idsession_idnamevalue
~id html~~session_id html~~name html~~value html~

- + diff --git a/test/tem_test.php.html b/test/tem_test.php.html index 385cecb..37ebdea 100644 --- a/test/tem_test.php.html +++ b/test/tem_test.php.html @@ -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.) --> - +

Please Log In Below

@@ -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~. --> - + @@ -40,7 +40,7 @@ special things: sub-templates and template tags. --> - + @@ -51,14 +51,14 @@ special things: sub-templates and template tags. --> - + - +

All your foobar:

@@ -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 --> - + - + - + - + @@ -91,6 +91,6 @@ special things: sub-templates and template tags. -->
~foo.html~~foo html~
- + diff --git a/uploader/uploader.html b/uploader/uploader.html index 3f0e610..9c713ef 100644 --- a/uploader/uploader.html +++ b/uploader/uploader.html @@ -6,7 +6,7 @@ - +

Upload a file:

@@ -24,6 +24,6 @@
- + -- 1.7.10.4