<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Savant Template Engine</title>
	<atom:link href="http://www.sitepoint.com/blogs/2005/07/26/savant-template-engine/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sitepoint.com/blogs/2005/07/26/savant-template-engine/</link>
	<description>News, opinion, and fresh thinking for web developers and designers. The official podcast of sitepoint.com.</description>
	<pubDate>Tue, 02 Dec 2008 07:46:11 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
		<item>
		<title>By: _Psih</title>
		<link>http://www.sitepoint.com/blogs/2005/07/26/savant-template-engine/#comment-8319</link>
		<dc:creator>_Psih</dc:creator>
		<pubDate>Sat, 27 Aug 2005 00:48:56 +0000</pubDate>
		<guid isPermaLink="false">127280874#comment-8319</guid>
		<description>To me it better for designer to learn basic PHP commands once, than to learn once Smarty, other time some other template language. At our office we came to the resolution, that Savant like template engines are more flexable. If designer needs something special, we always can write a plugin! We are developers by the way! If you write a quite big aplication, usualy it has it's own unique plugins, which make life much more easier. Some of them are universal, some not. In any case, I worked whith smarty... when i came to the table building whith colspans and rowspans at once, I started to hate it, because I had to write a lot of PHP code in aplication core, so that smatry could handle that table generation. Savant would make it much more easier, because you could write complex PHP code in template if you need it. And that was that thing that i needed in my case.</description>
		<content:encoded><![CDATA[<p>To me it better for designer to learn basic PHP commands once, than to learn once Smarty, other time some other template language. At our office we came to the resolution, that Savant like template engines are more flexable. If designer needs something special, we always can write a plugin! We are developers by the way! If you write a quite big aplication, usualy it has it&#8217;s own unique plugins, which make life much more easier. Some of them are universal, some not. In any case, I worked whith smarty&#8230; when i came to the table building whith colspans and rowspans at once, I started to hate it, because I had to write a lot of PHP code in aplication core, so that smatry could handle that table generation. Savant would make it much more easier, because you could write complex PHP code in template if you need it. And that was that thing that i needed in my case.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: pmjones</title>
		<link>http://www.sitepoint.com/blogs/2005/07/26/savant-template-engine/#comment-8207</link>
		<dc:creator>pmjones</dc:creator>
		<pubDate>Mon, 22 Aug 2005 23:23:08 +0000</pubDate>
		<guid isPermaLink="false">127280874#comment-8207</guid>
		<description>Hi Chris -- Regarding designers who need to learn a new language to get work done: either they get stuck learning the Smarty markup language, or they get stuck learning a minimal set of PHP commands.  If they're not a security threat, I'd say PHP itself is both easier and more flexible.</description>
		<content:encoded><![CDATA[<p>Hi Chris &#8212; Regarding designers who need to learn a new language to get work done: either they get stuck learning the Smarty markup language, or they get stuck learning a minimal set of PHP commands.  If they&#8217;re not a security threat, I&#8217;d say PHP itself is both easier and more flexible.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Alan Knowles</title>
		<link>http://www.sitepoint.com/blogs/2005/07/26/savant-template-engine/#comment-2297</link>
		<dc:creator>Alan Knowles</dc:creator>
		<pubDate>Wed, 31 Dec 1969 19:00:00 +0000</pubDate>
		<guid isPermaLink="false">127280874#comment-2297</guid>
		<description>&lt;p&gt;Great way to introduce XSS attacks into your code...&lt;br /&gt;
&lt;td&gt;&lt;?php echo $value['name'] ?&gt;&lt;/td&gt;&lt;/p&gt;

&lt;p&gt;Do you know where that came from? - is it safe?&lt;br /&gt;
Never trust your own code here, that may be safe today, but one day you will make a change to the backend code, and forget it is used at output time.. -&gt; opening the door to XXS attacks..&lt;/p&gt;

&lt;p&gt;This is why PHP style templates are just a bad idea.. - unless you copy and paste htmlspecialchars everywhere, in which case, you have to look through the trees to see the bugs... &lt;/p&gt;

&lt;p&gt;The output layer should default to escaping code if possible, and make it easy to find where escaping is not done, not the other way round.&lt;/p&gt;

&lt;p&gt;That's without getting into the undocumented madness that smarty and savant use with $object-&gt;assign()... &lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>Great way to introduce XSS attacks into your code&#8230;</p>
<td>< ?php echo $value['name'] ?></td>

<p>Do you know where that came from? - is it safe?<br />
Never trust your own code here, that may be safe today, but one day you will make a change to the backend code, and forget it is used at output time.. -> opening the door to XXS attacks..</p>
<p>This is why PHP style templates are just a bad idea.. - unless you copy and paste htmlspecialchars everywhere, in which case, you have to look through the trees to see the bugs&#8230; </p>
<p>The output layer should default to escaping code if possible, and make it easy to find where escaping is not done, not the other way round.</p>
<p>That&#8217;s without getting into the undocumented madness that smarty and savant use with $object->assign()&#8230; </p>]]></content:encoded>
	</item>
	<item>
		<title>By: charmedlover</title>
		<link>http://www.sitepoint.com/blogs/2005/07/26/savant-template-engine/#comment-2298</link>
		<dc:creator>charmedlover</dc:creator>
		<pubDate>Wed, 31 Dec 1969 19:00:00 +0000</pubDate>
		<guid isPermaLink="false">127280874#comment-2298</guid>
		<description>&lt;p&gt;Wow, quite a good post - and something very useful to me.  I write software and this templating system looks quite useful, as I don't want something as complex as Smarty.&lt;/p&gt;

&lt;p&gt;Although I have my own small templating system for Ottoman, but a future product I'm working on would be much easier to program and manage if I used Savant2.&lt;/p&gt;

&lt;p&gt;Again that's for the post.&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>Wow, quite a good post - and something very useful to me.  I write software and this templating system looks quite useful, as I don&#8217;t want something as complex as Smarty.</p>
<p>Although I have my own small templating system for Ottoman, but a future product I&#8217;m working on would be much easier to program and manage if I used Savant2.</p>
<p>Again that&#8217;s for the post.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Lachlan</title>
		<link>http://www.sitepoint.com/blogs/2005/07/26/savant-template-engine/#comment-2299</link>
		<dc:creator>Lachlan</dc:creator>
		<pubDate>Wed, 31 Dec 1969 19:00:00 +0000</pubDate>
		<guid isPermaLink="false">127280874#comment-2299</guid>
		<description>&lt;p&gt;In my work and projects I tend to use &lt;a href="http://www.sitepoint.com/article/beyond-template-engine"&gt;Brian Lozier's Template class&lt;/a&gt;. It uses pretty much exactly the same mechanism that Savant uses, e.g basically a fancy wrapper for a function-scoped call to &lt;a href="http://www.php.net/manual/en/function.extract.php"&gt;extract&lt;/a&gt;. Its light-weight, simple and does exactly what I need. For plugins I simply pass in view objects.&lt;/p&gt;

&lt;p&gt;One thing worth mentioning about templating in PHP is that it's not about separating PHP code from template files, its about separating business logic from presentation. There is nothing inherently evil about having code in your template files, so long as its code which exists solely to service the presentational aspects of what you are trying to accomplish. &lt;/p&gt;

&lt;p&gt;This separation isn't ever going to be solved entirely by the templating software, it's something which has to be separated by the developer as part of a conscious design decision.&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>In my work and projects I tend to use <a href="http://www.sitepoint.com/article/beyond-template-engine">Brian Lozier&#8217;s Template class</a>. It uses pretty much exactly the same mechanism that Savant uses, e.g basically a fancy wrapper for a function-scoped call to <a href="http://www.php.net/manual/en/function.extract.php">extract</a>. Its light-weight, simple and does exactly what I need. For plugins I simply pass in view objects.</p>
<p>One thing worth mentioning about templating in PHP is that it&#8217;s not about separating PHP code from template files, its about separating business logic from presentation. There is nothing inherently evil about having code in your template files, so long as its code which exists solely to service the presentational aspects of what you are trying to accomplish. </p>
<p>This separation isn&#8217;t ever going to be solved entirely by the templating software, it&#8217;s something which has to be separated by the developer as part of a conscious design decision.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: mutant</title>
		<link>http://www.sitepoint.com/blogs/2005/07/26/savant-template-engine/#comment-2300</link>
		<dc:creator>mutant</dc:creator>
		<pubDate>Wed, 31 Dec 1969 19:00:00 +0000</pubDate>
		<guid isPermaLink="false">127280874#comment-2300</guid>
		<description>&lt;p&gt;The template markup looks like PHP, but does it validate? I don't think so:&lt;br /&gt;
Parse error: syntax error, unexpected T_ENDFOREACH &lt;/p&gt;

&lt;p&gt;There is no "endforeach", while the language looks the same, it is still a custom markup.&lt;/p&gt;

&lt;p&gt;With smarty, this:&lt;br /&gt;
&#60;img src="{$image}/t1.jpg"/&#62;&lt;/p&gt;

&lt;p&gt;is nicer than:&lt;br /&gt;

 &#60;img src="&#60;?php echo $value['image']; ?&#62;"&#62;&lt;/p&gt;


&lt;p&gt;This isn't a "smarty is better" comment, but a "why choose one over the other if they are the same?" comment.&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>The template markup looks like PHP, but does it validate? I don&#8217;t think so:<br />
Parse error: syntax error, unexpected T_ENDFOREACH </p>
<p>There is no &#8220;endforeach&#8221;, while the language looks the same, it is still a custom markup.</p>
<p>With smarty, this:<br />
&lt;img src=&#8221;{$image}/t1.jpg&#8221;/&gt;</p>
<p>is nicer than:</p>
<p> &lt;img src=&#8221;&lt;?php echo $value[&#8217;image&#8217;]; ?&gt;&#8221;&gt;</p>
<p>This isn&#8217;t a &#8220;smarty is better&#8221; comment, but a &#8220;why choose one over the other if they are the same?&#8221; comment.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: zjcboy</title>
		<link>http://www.sitepoint.com/blogs/2005/07/26/savant-template-engine/#comment-2301</link>
		<dc:creator>zjcboy</dc:creator>
		<pubDate>Wed, 31 Dec 1969 19:00:00 +0000</pubDate>
		<guid isPermaLink="false">127280874#comment-2301</guid>
		<description>&lt;p&gt;Hey, &lt;/p&gt;

&lt;p&gt;I think I have a simpler solution(simpler in syntax). Just a class&lt;/p&gt;

&lt;p&gt;Template.class.php&lt;br /&gt;
--------------------&lt;/p&gt;


I use the template engine of my own. the syntax in the template file will be cleaner.  simple, yet it fits my neeeds.

&lt;code lang="php"&gt;
&lt; ?PHP
class Template
{
	var $path;
	var $file;
	var $_vars	= array();

	function Template()
	{
		require_once 'inc/html.php';
	}
	
	function set($k,$v)
	{
		$this-&gt;_vars[$k]	= $v;
	}

	function get($k)
	{
		return $this-&gt;_vars[$k];
	}

	function parse()
	{
		//import vars into this namespace
		extract($this-&gt;_vars);

		//start buffering output
		ob_start();

		require $this-&gt;file;

		//get the output in buffer
		$output = ob_get_contents();

		//clean buffer
		ob_end_clean();

		return $output;
	}
}
?&gt;&lt;/code&gt;&lt;p&gt;sample.tpl.php&lt;br /&gt;
---------------&lt;/p&gt;

&lt;code&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt; ?=$title?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;&lt; ?=$body?&gt;&lt;/body&gt;
&lt;/html&gt;&lt;/code&gt;&lt;p&gt;php script to use the template&lt;br /&gt;
------------------------------&lt;/p&gt;

&lt;code lang="php"&gt;
&lt; ?PHP
$tpl = new Template;
$tpl-&gt;file = 'sample.tpl.php';
$tpl-&gt;set('title', 'Hello');
$tpl-&gt;set('body','Hello, world!');
echo $tpl-&gt;parse();
?&gt;&lt;/code&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>Hey, </p>
<p>I think I have a simpler solution(simpler in syntax). Just a class</p>
<p>Template.class.php<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>I use the template engine of my own. the syntax in the template file will be cleaner.  simple, yet it fits my neeeds.</p>
<p><code lang="php">
< ?PHP
class Template
{
	var $path;
	var $file;
	var $_vars	= array();

	function Template()
	{
		require_once 'inc/html.php';
	}
	
	function set($k,$v)
	{
		$this->_vars[$k]	= $v;
	}

	function get($k)
	{
		return $this->_vars[$k];
	}

	function parse()
	{
		//import vars into this namespace
		extract($this->_vars);

		//start buffering output
		ob_start();

		require $this->file;

		//get the output in buffer
		$output = ob_get_contents();

		//clean buffer
		ob_end_clean();

		return $output;
	}
}
?></code>
</p><p>sample.tpl.php<br />
&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p><code>
<html>
<head>

</head>
<body>< ?=$body?></body>
</html></code>
</p><p>php script to use the template<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p><code lang="php">
< ?PHP
$tpl = new Template;
$tpl->file = 'sample.tpl.php';
$tpl->set('title', 'Hello');
$tpl->set('body','Hello, world!');
echo $tpl->parse();
?></code>
</p><p></p>]]></content:encoded>
	</item>
	<item>
		<title>By: Lachlan</title>
		<link>http://www.sitepoint.com/blogs/2005/07/26/savant-template-engine/#comment-2302</link>
		<dc:creator>Lachlan</dc:creator>
		<pubDate>Wed, 31 Dec 1969 19:00:00 +0000</pubDate>
		<guid isPermaLink="false">127280874#comment-2302</guid>
		<description>&lt;p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;br /&gt;
There is no "endforeach", while the language looks the same, it is still a custom markup.&lt;br /&gt;
&lt;/p&gt;&lt;/blockquote&gt;&lt;/p&gt;

&lt;p&gt;Actually, have a read of the &lt;a href="http://docs.php.net/en/language.control-structures.html"&gt;manual page&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;br /&gt;
 PHP offers an alternative syntax for some of its control structures; namely, if, while, for, foreach, and switch. In each case, the basic form of the alternate syntax is to change the opening brace to a colon (:) and the closing brace to endif;, endwhile;, endfor;, endforeach;, or endswitch;, respectively.&lt;br /&gt;
&lt;/p&gt;&lt;/blockquote&gt;&lt;/p&gt;

&lt;p&gt;Alternatively you could have looked at the list of &lt;a href="http://www.php.net/tokens"&gt;PHP parser tokens.&lt;/a&gt; Either place lists endforeach as valid PHP.&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>
<blockquote>
<p>
There is no &#8220;endforeach&#8221;, while the language looks the same, it is still a custom markup.
</p>
</blockquote>
</p><p>Actually, have a read of the <a href="http://docs.php.net/en/language.control-structures.html">manual page</a>:</p>
<p>
<blockquote>
<p>
 PHP offers an alternative syntax for some of its control structures; namely, if, while, for, foreach, and switch. In each case, the basic form of the alternate syntax is to change the opening brace to a colon (:) and the closing brace to endif;, endwhile;, endfor;, endforeach;, or endswitch;, respectively.
</p>
</blockquote>
</p><p>Alternatively you could have looked at the list of <a href="http://www.php.net/tokens">PHP parser tokens.</a> Either place lists endforeach as valid PHP.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Lachlan</title>
		<link>http://www.sitepoint.com/blogs/2005/07/26/savant-template-engine/#comment-2303</link>
		<dc:creator>Lachlan</dc:creator>
		<pubDate>Wed, 31 Dec 1969 19:00:00 +0000</pubDate>
		<guid isPermaLink="false">127280874#comment-2303</guid>
		<description>&lt;p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;br /&gt;
This is why PHP style templates are just a bad idea.. - unless you copy and paste htmlspecialchars everywhere, in which case, you have to look through the trees to see the bugs...&lt;/p&gt;&lt;/blockquote&gt;&lt;/p&gt;

&lt;p&gt;&lt;blockquote&gt;&lt;p&gt;The output layer should default to escaping code if possible, and make it easy to find where escaping is not done, not the other way round.&lt;/p&gt;&lt;/blockquote&gt;&lt;/p&gt;

&lt;p&gt;&lt;blockquote&gt;&lt;p&gt;That's without getting into the undocumented madness that smarty and savant use with $object-&gt;assign()... &lt;br /&gt;
&lt;/p&gt;&lt;/blockquote&gt;&lt;/p&gt;

&lt;p&gt;I'm not sure I follow, isn't having a presentation detail like calls to htmlspecialchars located in the presentation template a good thing? If you have your calls to htmlspecialchars sprinkled throughout your business logic layers how are you going to prevent double escaping? &lt;/p&gt;

&lt;p&gt;I tend to work on a &lt;a href="http://www.cs.unc.edu/~stotts/COMP204/contract.html"&gt;Programming By contract&lt;/a&gt; method, whereby my templating layer (the view) counts on the fact that it is being passed unescaped data. The templates job is to then format the data provided for presentation, if that presentation language is html then it gets escaped.  &lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>
<blockquote>
<p>
This is why PHP style templates are just a bad idea.. - unless you copy and paste htmlspecialchars everywhere, in which case, you have to look through the trees to see the bugs&#8230;</p>
</blockquote>
</p><p>
<blockquote>
<p>The output layer should default to escaping code if possible, and make it easy to find where escaping is not done, not the other way round.</p>
</blockquote>
</p><p>
<blockquote>
<p>That&#8217;s without getting into the undocumented madness that smarty and savant use with $object->assign()&#8230; 
</p>
</blockquote>
</p><p>I&#8217;m not sure I follow, isn&#8217;t having a presentation detail like calls to htmlspecialchars located in the presentation template a good thing? If you have your calls to htmlspecialchars sprinkled throughout your business logic layers how are you going to prevent double escaping? </p>
<p>I tend to work on a <a href="http://www.cs.unc.edu/~stotts/COMP204/contract.html">Programming By contract</a> method, whereby my templating layer (the view) counts on the fact that it is being passed unescaped data. The templates job is to then format the data provided for presentation, if that presentation language is html then it gets escaped.  </p>]]></content:encoded>
	</item>
	<item>
		<title>By: Olate</title>
		<link>http://www.sitepoint.com/blogs/2005/07/26/savant-template-engine/#comment-2304</link>
		<dc:creator>Olate</dc:creator>
		<pubDate>Wed, 31 Dec 1969 19:00:00 +0000</pubDate>
		<guid isPermaLink="false">127280874#comment-2304</guid>
		<description>&lt;p&gt;There is currently discussion on the Savant mailing list about a new function in the 2.4 release which will handle all the escaping for you. So instead of using echo, which you rightly said might cause XSS problems, you would use the built in Savant function and then any necessary escaping would be done for you.&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>There is currently discussion on the Savant mailing list about a new function in the 2.4 release which will handle all the escaping for you. So instead of using echo, which you rightly said might cause XSS problems, you would use the built in Savant function and then any necessary escaping would be done for you.</p>]]></content:encoded>
	</item>
</channel>
</rss>
