X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=doc%2Ftemplate.php.txt;h=6a6431949ec2231a2b642f66d50d7234bc626210;hb=9a3136a5bee66e1055ffb566373952b6054dd7bf;hp=416b6ac2d650ce0ef3ae6e97093119d1cf5e9001;hpb=96fa997ecdcd1e7a6cb27c61969a1c3ce6c648f8;p=wfpl.git diff --git a/doc/template.php.txt b/doc/template.php.txt index 416b6ac..6a64319 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