I wanted to know how people here in DW use which templating system

I prefer to make my own so that way it is guaranteed to be secure and with all the features I need. And the process of making the template is fun too. But if I ever need to scratch out a quick cms then I would use mediawiki with custom extensions.

Member Avatar for diafol

I've started to use Rain TPL. Used to use Smarty.

Rain seems more lightweight and user friendly. However the documentation isn't as good. But, once you've used one templating system, I suppose the basics are pretty much the same in each.

I also use my own, which is just a collection of common includes, so not a proper grown-up templating system, but that's they way I like to work most of the time.

I prefer to make my own so that way it is guaranteed to be secure and with all the features I need. And the process of making the template is fun too. But if I ever need to scratch out a quick cms then I would use mediawiki with custom extensions.

Do you code simple includes or just full fledged ones?

I've started to use Rain TPL. Used to use Smarty.

Rain seems more lightweight and user friendly. However the documentation isn't as good. But, once you've used one templating system, I suppose the basics are pretty much the same in each.

I also use my own, which is just a collection of common includes, so not a proper grown-up templating system, but that's they way I like to work most of the time.

Do you still use Rain TPL? How is it doing? I'm still hesitating jump into smarty wagon ;)

Member Avatar for diafol

Rain TPL much easier once you know the basics of templating. Perhaps Smarty is the 'industry standard' and has better documentation. I would imagine that starting with the basic functions of Smarty will get you going.
The demo pages are a good starter, although unless you've got a little understanding of OOP, it can look daunting.
Haven't used a templater for a while. Still using includes. I find them far more flexible. Okay, the echoing of php variables is a pain with the full syntax every time, but I'm not too bothered about that.

Has anyone else ever taken the XML/XSL approach?

I found generating XML representations of my output and using XSL style sheets to do the transformations with the php XSL extension to quite powerful and surprisingly fast.

It also truly separates your php from your template while also being a w3 standard.

I use smarty. For me it makes it easy to share, since most people I share code with also use smarty. I have to say that the docs are a definite plus. XML/XSLT comes in handy once in a while, so I use a smarty plugin to handle those situations.

Rain TPL much easier once you know the basics of templating. Perhaps Smarty is the 'industry standard' and has better documentation. I would imagine that starting with the basic functions of Smarty will get you going.
The demo pages are a good starter, although unless you've got a little understanding of OOP, it can look daunting.
Haven't used a templater for a while. Still using includes. I find them far more flexible. Okay, the echoing of php variables is a pain with the full syntax every time, but I'm not too bothered about that.

Thanks Ardav. I will try to jump into smarty

Has anyone else ever taken the XML/XSL approach?

I found generating XML representations of my output and using XSL style sheets to do the transformations with the php XSL extension to quite powerful and surprisingly fast.

It also truly separates your php from your template while also being a w3 standard.

Haven't even tried that. Any demo/Short tutorial for quick look?

I use smarty. For me it makes it easy to share, since most people I share code with also use smarty. I have to say that the docs are a definite plus. XML/XSLT comes in handy once in a while, so I use a smarty plugin to handle those situations.

Here is another encouragement to use smarty!

XML/XSL example

index.php

<?php
/**
 * This script loads the RSS feed (XML) from DaniWeb's PHP Forum
 * It then performs a an XSL Transformation to display it as formatted HTML
 * 
 * @see http://www.daniweb.com/forums/rss17.xml
 */

$doc = new DOMDocument();
$xsl = new XSLTProcessor();

$doc->load('templates/index.xsl');
$xsl->importStyleSheet($doc);

$doc->load('http://www.daniweb.com/forums/rss17.xml');
$html = $xsl->transformToXML($doc);

echo $html;

templates/index.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
	<xsl:template match="/">
		<html xmlns="http://www.w3.org/1999/xhtml">
			<head>
				<title><xsl:value-of select="rss/channel/title"/></title>
				<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
			</head>
			<body>
				<xsl:for-each select="/rss/channel/item">
					<h2><a href="{link}" ><xsl:value-of select="title"/></a></h2>
					<p>Date: <xsl:value-of select="pubDate"/> </p >
					<p><xsl:value-of select="description"/> </p>
				</xsl:for-each>
			</body>
		</html>
	</xsl:template>
</xsl:stylesheet>

Thats about as simple as it gets.

XSL is extremely powerful once you learn its syntax.
Your output is not limited to just html either, anything that is composed of an XML structure can be created just by changing the template.

Benefit of using XML/XSL to generate HTML is that it forces your output to be valid XML markup. Correct nesting, end tags etc.

Thanks a lot. Three questions on that:
1. Is there tutorial for that?
2. Example website done fully using the technique?
3. Can I create different templates without re-coding the php part (I guess yes?)

1. Are you asking about a tutorial for my code or a tutorial for XSL in general? XSL is a w3 standard. Coupled with XPath and XQuery for navigating and making node/attribute selections. You should be able to find a million examples online. I have several books from Wrox on the topic as well.

2. See your PM. There is also a CMS built entirely using xsl. http://symphony-cms.com/ I have never worked with it so I'm not sure how powerful/flexible their setup is.

3. In my template engine that php is actually part of a class. That is just a really simplified snippet of code.

In the sites i've built using xml/xsl I usually use the DOMDocument to create blocks of xml at a modular level which provides a nice hook for being able to cache the final xml without having to regenerate it every time.

In the last year I've moved on to working with the zend framework primarily and haven't done much with xml/xsl but it still one of my favorite methods for templating. If you're familiar with ZF then this might be of interest (http://www.contentwithstyle.co.uk/content/zend-framework-xsl-and-self-serializing-views) I have been meaning to see how well i can integrate the two but haven't had the time lately.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.