Date: 07/27/01
- Next message: Richard Archer: "Re: [phplib] Template extensions & PHP in templates"
- Previous message: Tarique Sani
email protected>>: "Re: [phplib] Template extensions & PHP in templates" - In reply to: Peter Bowyer: "[phplib] Inserting the correct template block"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
At 9:01 PM +0100 26/7/01, Peter Bowyer wrote:
>I'm sure I'm not using the tempate class correctly and there's something
>I've missed - can someone help me please???
I notice you're only passing two arguments to set_block. I'm not aware
of a version of template.inc that has this behaviour, so I suspect
you're using a fairly old one (or a heavily modified one).
Your problem certainly highlights some problems with the way loadfile
determines whether or not a variable contains data that should be
loaded from disk! I'm starting to wonder whether the logic involved in
waiting until the last minute to load in a template file is more costly
than just loading it in from this->set_file and knowing it's there.
My test below runs fine with my version of template.inc, which you
can grab from:
http://mel01.juggernaut.com.au/templates/phplib/template.txt
The way I would go about this problem (note, I've simplified your
image tag template file somewhat, but the logic is the same):
::::::::::::::
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=true;
# 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_var}
$t->set_block("img_tags", "img_block", "img_block_var");
# extract from "img_tags" the block named "swf_block", leaving a
# reference to {swf_block_var}
$t->set_block("img_tags", "swf_block", "swf_block_var");
# 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", " height=10 width=10 "); # sample data only
if (ereg("\.swf$", $testdata[$cc])) {
$t->set_var("img_block_var", ""); # delete the image block
$t->parse("swf_block_var", "swf_block"); # fill in the swf block
}
else {
$t->set_var("swf_block_var", ""); # delete the swf block
$t->parse("img_block_var", "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");
?>
::::::::::::::
debug output
::::::::::::::
loadfile: loaded ./conditionaltest2.tmpl into img_tags
set_var: (with scalar) img_tags = '<!-- BEGIN img_block --> img src="images/{IMAGE}" {IMGSIZE}<br> <!-- END img_block --> <!-- BEGIN swf_block --> swf src="images/{IMAGE}" {IMGSIZE}<br> <!-- END swf_block --> '
get_var (with scalar) img_tags = '<!-- BEGIN img_block --> img src="images/{IMAGE}" {IMGSIZE}<br> <!-- END img_block --> <!-- BEGIN swf_block --> swf src="images/{IMAGE}" {IMGSIZE}<br> <!-- END swf_block --> '
set_var: (with scalar) img_block = ' img src="images/{IMAGE}" {IMGSIZE}<br> '
set_var: (with scalar) img_tags = '{img_block_var} <!-- BEGIN swf_block --> swf src="images/{IMAGE}" {IMGSIZE}<br> <!-- END swf_block --> '
get_var (with scalar) img_tags = '{img_block_var} <!-- BEGIN swf_block --> swf src="images/{IMAGE}" {IMGSIZE}<br> <!-- END swf_block --> '
set_var: (with scalar) swf_block = ' swf src="images/{IMAGE}" {IMGSIZE}<br> '
set_var: (with scalar) img_tags = '{img_block_var} {swf_block_var} '
set_var: (with scalar) IMAGE = 'image1.gif'
set_var: (with scalar) IMGSIZE = ' height=10 width=10 '
set_var: (with scalar) swf_block_var = ''
get_var (with scalar) img_block = ' img src="images/{IMAGE}" {IMGSIZE}<br> '
set_var: (with scalar) img_block_var = ' img src="images/image1.gif" height=10 width=10 <br> '
get_var (with scalar) img_tags = '{img_block_var} {swf_block_var} '
get_var (with scalar) IMG = ''
set_var: (with scalar) IMG = ' img src="images/image1.gif" height=10 width=10 <br> '
set_var: (with scalar) IMAGE = 'movie2.swf'
set_var: (with scalar) IMGSIZE = ' height=10 width=10 '
set_var: (with scalar) img_block_var = ''
get_var (with scalar) swf_block = ' swf src="images/{IMAGE}" {IMGSIZE}<br> '
set_var: (with scalar) swf_block_var = ' swf src="images/movie2.swf" height=10 width=10 <br> '
get_var (with scalar) img_tags = '{img_block_var} {swf_block_var} '
get_var (with scalar) IMG = ' img src="images/image1.gif" height=10 width=10 <br> '
set_var: (with scalar) IMG = ' img src="images/image1.gif" height=10 width=10 <br> swf src="images/movie2.swf" height=10 width=10 <br> '
set_var: (with scalar) IMAGE = 'movie3.swf'
set_var: (with scalar) IMGSIZE = ' height=10 width=10 '
set_var: (with scalar) img_block_var = ''
get_var (with scalar) swf_block = ' swf src="images/{IMAGE}" {IMGSIZE}<br> '
set_var: (with scalar) swf_block_var = ' swf src="images/movie3.swf" height=10 width=10 <br> '
get_var (with scalar) img_tags = '{img_block_var} {swf_block_var} '
get_var (with scalar) IMG = ' img src="images/image1.gif" height=10 width=10 <br> swf src="images/movie2.swf" height=10 width=10 <br> '
set_var: (with scalar) IMG = ' img src="images/image1.gif" height=10 width=10 <br> swf src="images/movie2.swf" height=10 width=10 <br> swf src="images/movie3.swf" height=10 width=10 <br> '
set_var: (with scalar) IMAGE = 'image4.jpg'
set_var: (with scalar) IMGSIZE = ' height=10 width=10 '
set_var: (with scalar) swf_block_var = ''
get_var (with scalar) img_block = ' img src="images/{IMAGE}" {IMGSIZE}<br> '
set_var: (with scalar) img_block_var = ' img src="images/image4.jpg" height=10 width=10 <br> '
get_var (with scalar) img_tags = '{img_block_var} {swf_block_var} '
get_var (with scalar) IMG = ' img src="images/image1.gif" height=10 width=10 <br> swf src="images/movie2.swf" height=10 width=10 <br> swf src="images/movie3.swf" height=10 width=10 <br> '
set_var: (with scalar) IMG = ' img src="images/image1.gif" height=10 width=10 <br> swf src="images/movie2.swf" height=10 width=10 <br> swf src="images/movie3.swf" height=10 width=10 <br> img src="images/image4.jpg" height=10 width=10 <br> '
loadfile: loaded ./conditionaltest1.tmpl into page
set_var: (with scalar) page = '<HTML> <BODY> {IMG} </BODY> </HTML> '
get_var (with scalar) page = '<HTML> <BODY> {IMG} </BODY> </HTML> '
set_var: (with scalar) output = '<HTML> <BODY> img src="images/image1.gif" height=10 width=10 <br> swf src="images/movie2.swf" height=10 width=10 <br> swf src="images/movie3.swf" height=10 width=10 <br> img src="images/image4.jpg" height=10 width=10 <br> </BODY> </HTML> '
get_var (with scalar) output = '<HTML> <BODY> img src="images/image1.gif" height=10 width=10 <br> swf src="images/movie2.swf" height=10 width=10 <br> swf src="images/movie3.swf" height=10 width=10 <br> img src="images/image4.jpg" height=10 width=10 <br> </BODY> </HTML> '
img src="images/image1.gif" height=10 width=10
swf src="images/movie2.swf" height=10 width=10
swf src="images/movie3.swf" height=10 width=10
img src="images/image4.jpg" height=10 width=10
::::::::::::::
page output
::::::::::::::
<html>
<body>
img src="images/image1.gif" height=10 width=10 <br>
swf src="images/movie2.swf" height=10 width=10 <br>
swf src="images/movie3.swf" height=10 width=10 <br>
img src="images/image4.jpg" height=10 width=10 <br>
</body>
</html>
-- Abbestellen mit Mail an: phplib-unsubscribe <email protected> Kommandoliste mit Mail an: phplib-help <email protected>
- Next message: Richard Archer: "Re: [phplib] Template extensions & PHP in templates"
- Previous message: Tarique Sani
email protected>>: "Re: [phplib] Template extensions & PHP in templates" - In reply to: Peter Bowyer: "[phplib] Inserting the correct template block"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

