[Petal] Re: Strange parsing of HTML
Christopher R. Baker
cbaker@cbaker.org
Fri, 27 Sep 2002 13:49:49 -0700
Having just arrived here, I was browsing through the archives looking for sample templates. One I could find was posted as a base64 attachment at http://lists.webarch.co.uk/pipermail/petal/2002-August/000098.html
For those coming late to the show, Here's test.tmpl in plain english:
<?xml version="1.0" encoding="iso-8859-1"?>
<!--?
# Template: test.tmpl
# Created: 07-23-2002
# Modified: 08-14-2002
# Author: wlm
# Description: Template to do terrible things to test Petal template language.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content="HTML Tidy for Windows (vers 1st January 2002), see www.w3.org" />
<title>Petal Stress Test Template</title>
</head>
<!--? <?petal:include file="includes/header.tmpl"?> -->
<body>
<h3>The tags:</h3>
<ul>
<li>error_message: <span petal:content="error_message">Error</span></li>
<li>first_name: <span petal:content="first_name">First</span></li>
<li>last_name: <span petal:content="last_name">Last</span></li>
<li>email: <span petal:content="email">Email</span></li>
<li>
Students List<br />
<ul petal:repeat="student students">
<li><?petal:var name="encode: student.first_name"?>
<?petal:var name="encode: student.last_name"?>
- <?petal:var name="encode: student.email"?>
</li>
</ul>
</li>
</ul>
<hr size="9" width="95%" />
<h3>The Non-Working Tests</h3>
<h4>String modifier error II</h4>
<p>This example illustrates how the __count__ value is not being properly handled in string statements. It also shows how the name attribute is not being properly built in an input element as well.</p>
<ul petal:repeat="student students">
<li><?petal:var name="string:$__count__ - $encode:student.first_name"?>
<?petal:var name="encode: student.last_name"?>
- <?petal:var name="encode: student.email"?> -
<input petal:attr="name string:first_name${__count__}" petal:attr="value student.first_name" type="string" />
</li>
</ul>
<h4>Rewrite error</h4>
<p>This example shows how Petal is changing some HTML attributes when creating its output. In this example, values are changed to real spaces which is not the desired result when creating XHTML output. I built this as a table to try to repeat a problem I saw where adding &nbsp; attributes was causing Petal to add an extra row. It's probably a problem with my other template.</p>
<table border="1">
<tr>
<td>Column 1</td>
<td>Column 2</td>
</tr>
<tr>
<td colspan="2"><input type="button" value="Button 1"> <input type="button" value="Button 2"></td>
</tr>
</table>
<h4>HTML Comments error</h4>
<p>This example illustrates how HTML comments get oddly parsed when using the XHTML/XHTML input/output settings in Petal.</p>
<!-- This is a test. It will appear at the top. A tag will cause the rest of this text to go away <p> LOST TEXT -->
<!--?
<p> </p>
<hr size="9" width="95%">
<h3>The Working Tests</h3>
<p>String modifier error</p>
<p><a petal:attr="href string:test.cgi?rm=edit_coach&fn=$first_name"><?petal:var name="encode: first_name"?>
<?petal:var name="encode: last_name"?>
</a></p>
<p><a petal:attr="href string:mailto://$email"><span petal:content="encode: email">Email</span></a></p>
<p>Stacked petal tags</p>
<p class="error" petal:if="error_message" petal:content="error_message">Error</p>
<hr size="5" width="75%">
<p>1. A tag within an html tag property doesn't work, in some cases. Works if there is no include tag above it. Does not work if there is an include tag above it.
<br />
<a href="mailto:<?petal:var name="email"?>">Email</a>
</p>
<hr size="5" width="75%">
<p>2. Two tags in a row will only show the first, or nothing at all. I'm not sure why this format isn't working at all in this test template. It does work in another of my templates. Perhaps it is due to the error in the above tag. Commenting out the above tag doesn't seem to make any difference, though. Do tags inside of comments get executed?
<br />
<?petal:var name="encode: first_name"?> <br />
<?petal:var name="encode: first_name"?> <?petal:var name="encode: last_name"?>
</p>
<hr size="5" width="75%">
<p>3. Includes don't always work. Try moving one of the tags to the top and see the results. Rather curious... If you move the footer to the top, you'll see that it gets shown twice if you have 2 footer includes statements following it; if you remove the last one just above the /body tag, you'll see the one after header isn't working, but further ones do. There is apparently something in the header.tmpl document which is causing Petal to not perform the next includes. In fact, you can keep adding footer includes and get more and more results as expected.
<br />
<?petal:include file="includes/header.tmpl"?>
<p>This include won't get displayed</p>
<?petal:include file="includes/footer.tmpl"?>
<hr size="5" width="75%">
<p>Creating a link</p>
<ul petal:repeat="student students">
<li><a href=""><?petal:var name="encode: student.first_name"?> <?petal:var name="encode: student.last_name"?> - <?petal:var name="encode: student.email"?></a></li>
</ul>
<hr size="5" width="75%">
<h3>End Tests</h3>
<?petal:include file="includes/footer.tmpl" taint="1"?>
-->
</body>
</html>
--
Christopher R. Baker
Tune Smith / Programmer
http://cbaker.org