On 5/25/09 8:48 PM, "Nathan Rixham" <nrixham@xxxxxxxxx> wrote: > Sancar Saran wrote: >> <?php >> $content = 'No Comments'; >> if(isset($comments) and is_array($comments) and count($comments) > 0 ) { >> $content = ''; >> foreach( $comments as $index => $comment ) : $content. = "<a href='". >> $comment->link."'>".$comment->title."</a>"; endforeach; >> } >> ?> >> >> <h2>Comments</h2> >> <div id="comments"> >> <?=$content?> >> </div> >> >> index.php >> ob_start(); >> require('template.php'); >> echo ob_get_clean(); >> >> >> I'm still do not understand for complex template system requirement. > > I just _need_ the two abstracted. > > php must have no html in it > html template must contain no php i can achieve that separation in phplib using blocks, i.e blocks of template that may be repeatedly replaced, hierarchically if so desired. presumably smarty has something equivalent. but, naturally, this doesn't meet your "pull" requirement. hoever, i sometimes find that some mixing is inevitable. for example, if i am listing music recordings but not using a table, just a list. my template might be (leaving out the classes and ids. and humor me in my old-fashioned tag preferences): <!-- BEGIN songblock --> <li><b>{artist}</b>, {disk} <i>{label}</i></li> <!-- END songblock --> that works but if my database entry for a given disk has no information on the label then the html output looks a but nasty: <li><b>Mika Miko</b>, We Be Xuxa <i></i></li> which sort of works but offends my sensibilities. since phplib doesn't have a way to make a chunk of template conditional (other than with a block, which would become a pita as you can imagine from the above), i sigh, shrug and move the <i></i> in the conditional in the script. oh well. purity is idealistic. a possible solution would be to define macros in the template, maybe... {MACRO:label=, <i>{label}</i>} that would give me an optional comma and get rid of the space if there's no label data while keeping all html out of the script. while this achieves the ideal of separation i'm not sure it's really more practical than the impurity of having some html bits in the script. having practical experience with just one approach i can only speak theoretically of the other. (btw: macros can in fact be done in phplib templates by putting each macro in a template file of its own, but that doesn't sound too practical in the long run, does it?) on another different topic, i would make independence of the output language a requirement of the template scheme. e.g. besides html, i use phplib templates to generate plain text emails, sql files, json ajax responses, whatever... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php