Re: [Phplib-users] Template Class
Brought to you by:
nhruby,
richardarcher
From: Richard A. <rh...@ju...> - 2001-08-16 06:02:18
|
At 12:01 PM +0700 16/8/01, Abu Hudzaefah wrote: >I saw there is no special variabel to select value, using template >(IF), example: > >{TMPL_IF VAR=1} > do 1 >{TMPL_ELSE} > do 2 >{/TMPL_IF} > >how to do it on template class? You should place all your application logic in your PHP script. Here's an example that was posted to the old list. ...Richard. :::::::::::::: conditionaltest1.tmpl :::::::::::::: <HTML> <BODY> {IMG} </BODY> </HTML> :::::::::::::: conditionaltest2.tmpl :::::::::::::: <!-- BEGIN img_block --> img src="images/{IMAGE}" {IMGSIZE}<br> <!-- END img_block --> <!-- BEGIN swf_block --> swf src="images/{IMAGE}" {IMGSIZE}<br> <!-- END swf_block --> :::::::::::::: conditionaltest.php :::::::::::::: <?php include("template.inc"); $testdata = array("image1.gif", "movie2.swf", "movie3.swf", "image4.jpg"); $t = new Template(".","comment"); $t->debug=0; # load the page from conditionaltest1.tmpl into "page" # load image tag from conditionaltest2.tmpl into "img_tags" $t->set_file(array("page" => "conditionaltest1.tmpl", "img_tags" => "conditionaltest2.tmpl")); # extract from "img_tags" the block named "img_block", leaving a # reference to {img_block_tag} $t->set_block("img_tags", "img_block", "img_block_tag"); # extract from "img_tags" the block named "swf_block", leaving a # reference to {swf_block_tag} $t->set_block("img_tags", "swf_block", "swf_block_tag"); # loop through our test data for ($cc = 0; $cc < count($testdata) ; $cc++) { # set variables with substitution data $t->set_var("IMAGE", $testdata[$cc]); $t->set_var("IMGSIZE", "size"); if (ereg("\.swf$", $testdata[$cc])) { $t->set_var("img_block_tag", ""); # delete the image block $t->parse("swf_block_tag", "swf_block"); # fill in the swf block } else { $t->set_var("swf_block_tag", ""); # delete the swf block $t->parse("img_block_tag", "img_block"); # fill in the img block } # append this image tag to the IMG block $t->parse ("IMG", "img_tags", true); } $t->parse("output", "page"); $t->p("output"); ?> :::::::::::::: output :::::::::::::: <html> <body> img src="images/image1.gif" size<br> swf src="images/movie2.swf" size<br> swf src="images/movie3.swf" size<br> img src="images/image4.jpg" size<br> </body> </html> |