Re: working on a template system...

From: Date: Thu, 29 Jun 2006 16:49:01 +0000
Subject: Re: working on a template system...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-238925@lists.php.net to get a copy of this message
*joining the fray a little late* What is the difference between this, Smarty and template.inc? I have found Smarty to be unusable in my situation where a graphic designer needs to be able to edit the html and is easily confused by non-html. So, I am using template.inc which is apparently old (PHP 3) but seems to work great even with PHP 4.1. Another question is whether it will work with PHP 5? Charlene sempsteen wrote:
hi, i'm working on a template system. Basically i'm building raw contents in arrays and then put them in templates by some special tags. for loop systems my basic array structure is like this: $array['key'][]['keyword'] = ... for example, for a bulletin board system, array structure for categories is something like this: $array['categories'][]['text_category_name'] = ... it is looped through database recordset, so final array for 2 categories can be: $array['categories'][0]['text_category_name'] = 'programming' $array['categories'][1]['text_category_name'] = 'life' template file structure for loops is something like this (ex, categories): <!-- loop|categories:bof --> <tr> <td>[$text_category_name$]</td> </tr> <!-- loop|categories:eof --> i can easily loop this template and replace [$text_category_name] for every category set in the array. after removing the comment tags i get the final content: <tr> <td>programming</td> </tr> <tr> <td>life</td> </tr> But i'm stuck with nested loops. For example i want to put related forums after each categories. array structure is: $array['categories'][0]['text_category_name'] = programming $array['categories'][0]['forums'][0]['text_forum_name'] = php $array['categories'][0]['forums'][1]['text_forum_name'] = ruby $array['categories'][1]['text_category_name'] = life $array['categories'][1]['forums'][0]['text_forum_name'] = music $array['categories'][1]['forums'][1]['text_forum_name'] = sports template structure is: <!-- loop|categories:bof --> <tr> <td>[$text_category_name$]</td> </tr> <!-- loop|forums:bof --> <tr> <td>[$text_forum_name$]</td> </tr> <!-- loop|forums:eof --> <!-- loop|categories:eof --> i've written some functions, used them recursively but it didn't work. actually i couldn't find the true logic. note that it isn't a limited array. it can have messages under each forums, peoples under each messages, so on.. help me find the true approach to handle this. thank you.


« previous php.general (#238925) next »