Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > PHP

Reply
 
LinkBack Thread Tools Display Modes
Old 11-08-2009, 09:14 AM   #1 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 832
DJMaze is on a distinguished road
Question [Give Opinion] New template system?

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&amp;foo">test</a>

<form>
<textarea></textarea>
<br/>
<input/>
</form>
<hr/>

   	<xsl:if test="price &gt; 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 &gt; 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&amp;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>
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 11-09-2009, 12:23 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,700
sde is on a distinguished road
I like the concept for apps that would utilize a single template file for a single web page.

In something like Drupal though, most of the templates are just chunks of content within a full page.

I'm sure you could write a theme engine for it, but the advantage of being able to view it in FF directly from a template view wouldn't be that practical.. although I guess you could still keep the content valid within the scope of the template file.

Another thing going against Drupal with this system is that it uses API call from module to load CSS and Javascript.
__________________
Mike
sde is offline   Reply With Quote
Old 11-10-2009, 01:24 PM   #3 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 832
DJMaze is on a distinguished road
XML Parser doesn't need a whole document, it can parse in chunks.
First you parse a header.html, then some modules and blocks and then the footer.html
At the end you eval() the whole document (the TAL/XSLT is converted to PHP code).
So, modules can still add/remove any headers (CSS, JavaScript, meta and link).

And yes, you need to make API calls (which makes it slower).
But, how easy is it to design a Drupal website where html is not seperated from code?
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
can anyone give me another way of solving this problem? neeven Standard C, C++ 1 10-24-2006 10:26 AM
Will someone give some simple c++ tests? slashdot Standard C, C++ 12 08-04-2005 02:25 PM
I need a code to give freebies on my site zipmagazine HTML, XML, Javascript, AJAX 1 09-22-2004 03:48 AM
New Design Opinion Please sde Lounge 32 07-01-2004 11:16 AM
Easy Template System randy PHP 0 05-27-2003 09:33 AM


All times are GMT -8. The time now is 10:18 PM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting