Hey all,
i want your opinion
if you are familiar with template systems.
You probably worked with Smarty, phpBB, Drupal, etc. etc.
Think about it and what did you like and dislike about these?
Did you ever used XSLT or Zope's TAL?
Do you like to have html/xhtml/xml templates that are validated at compile time and don't screw up the layout when viewing in a browser?
For example open a phpBB template in Firefox and you know what i mean.
What if i combined TAL and XSLT into one template parser that uses
PHP: XML Parser so that templates are still 100% valid when viewing in a browser?
Example:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
i18n:attributes="lang lang">
<head>
<title tal:content="title">
Place for the page title
</title>
<script type="text/javascript"><![CDATA[
$LNG["Nothing changed"] = "Nothing changed!";
$LNG["Submitting"] = "Submitting...";
]]></script>
</head>
<body>
<h1 tal:content="title">text <b>replaced</b> by item</h1>
<table>
<tr tal:repeat="track catalog/cd">
<td tal:content="track/title">Track title</td>
<td tal:content="track/artist">Name of artist</td>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td tal:condition="repeat/cd/odd" tal:content="repeat/cd/index">odd</td>
<td tal:condition="repeat/cd/even" tal:content="repeat/cd/index">even</td>
</tr>
</xsl:for-each>
</table>
<p tal:condition="identified"> Welcome member … </p>
<p tal:else-if="bot"> Welcome bot </p>
<p tal:else=""> Please login before accessing this page </p>
<b tal:omit-tag="not:bold">Not bold</b>
<a href="http://example.com/?test&foo">test</a>
<form>
<textarea></textarea>
<br/>
<input/>
</form>
<hr/>
<xsl:if test="price > 10">
cool
</xsl:if>
<xsl:for-each select="catalog/cd">
<xsl:value-of select="title"/>
<xsl:if test="position()!=last()">
<xsl:text>, </xsl:text>
</xsl:if>
<xsl:if test="position()=last()-1">
<xsl:text> and </xsl:text>
</xsl:if>
<xsl:if test="position()=last()">
<xsl:text>!</xsl:text>
</xsl:if>
</xsl:for-each>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<xsl:choose>
<xsl:when test="price > 10">
<td bgcolor="#ff00ff">
<xsl:value-of select="artist"/></td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select="artist"/></td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
</table>
</body>
</html>
output
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="">
<head>
<title>My example</title>
<script type="text/javascript"><![CDATA[
$LNG["Nothing changed"] = "Nothing changed!";
$LNG["Submitting"] = "Submitting...";
]]></script>
</head>
<body>
<h1>My example</h1>
<table>
<tr>
<td>Sing a song</td>
<td>John Doe</td>
</tr>
<tr>
<td>Sing another song</td>
<td>John Doe</td>
</tr>
<tr></tr>
<tr>
<td>0</td>
</tr>
<tr>
<td>1</td>
</tr>
</table>
<p> Please login before accessing this page </p>
Not bold
<a href="http://example.com/?test&foo">test</a>
<form action="">
<textarea cols="20" rows="2"></textarea>
<br />
<input />
</form>
<hr />
Sing a song and Sing another song
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<tr>
<td>Sing a song</td>
<td bgcolor="#ff00ff">John Doe</td>
<tr>
<td>Sing another song</td>
<td>John Doe</td>
</tr>
</table>
</body>
</html>