<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Simple Templating</title>
	<atom:link href="http://blog.kevburnsjr.com/simple-templating/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.kevburnsjr.com/simple-templating</link>
	<description>Web Application Engineer</description>
	<lastBuildDate>Sun, 18 Dec 2011 02:08:36 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: KevBurnsJr</title>
		<link>http://blog.kevburnsjr.com/simple-templating/comment-page-1#comment-1929</link>
		<dc:creator>KevBurnsJr</dc:creator>
		<pubDate>Tue, 19 May 2009 03:03:37 +0000</pubDate>
		<guid isPermaLink="false">http://kevburnsjr.com/?p=222#comment-1929</guid>
		<description>Template::render() does sound rather verby.  

I think the benefit might come when you can add additional methods for other templates types, like Template::renderSmarty() where both render and renderSmarty might share some logic that would be best encapsulated by a private method on the Template class.

But you&#039;re right.  An autoloaded static class with 1 static method and no properties is essentially a global function.</description>
		<content:encoded><![CDATA[<p>Template::render() does sound rather verby.  </p>
<p>I think the benefit might come when you can add additional methods for other templates types, like Template::renderSmarty() where both render and renderSmarty might share some logic that would be best encapsulated by a private method on the Template class.</p>
<p>But you&#8217;re right.  An autoloaded static class with 1 static method and no properties is essentially a global function.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sandeep Shetty</title>
		<link>http://blog.kevburnsjr.com/simple-templating/comment-page-1#comment-1928</link>
		<dc:creator>Sandeep Shetty</dc:creator>
		<pubDate>Mon, 18 May 2009 04:42:07 +0000</pubDate>
		<guid isPermaLink="false">http://kevburnsjr.com/?p=222#comment-1928</guid>
		<description>I&#039;ve been using this technique since a while now and its interesting to see someone else come up with the exact same thing. Then again, this seems to be the solution that most experienced PHP developers will naturally arrive at as a way to effectively use PHP as the templating language that it is.

On another note, a class that only has one static method does not feel like it deserves to be a class since being a class gives it no advantages. Why not just make it a function (template_render)?

http://sandeep.shetty.in/2009/04/procedural-programming-is-not-bad-thing.html</description>
		<content:encoded><![CDATA[<p>I&#8217;ve been using this technique since a while now and its interesting to see someone else come up with the exact same thing. Then again, this seems to be the solution that most experienced PHP developers will naturally arrive at as a way to effectively use PHP as the templating language that it is.</p>
<p>On another note, a class that only has one static method does not feel like it deserves to be a class since being a class gives it no advantages. Why not just make it a function (template_render)?</p>
<p><a href="http://sandeep.shetty.in/2009/04/procedural-programming-is-not-bad-thing.html" rel="nofollow">http://sandeep.shetty.in/2009/04/procedural-programming-is-not-bad-thing.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: KevBurnsJr</title>
		<link>http://blog.kevburnsjr.com/simple-templating/comment-page-1#comment-1464</link>
		<dc:creator>KevBurnsJr</dc:creator>
		<pubDate>Mon, 13 Apr 2009 02:40:48 +0000</pubDate>
		<guid isPermaLink="false">http://kevburnsjr.com/?p=222#comment-1464</guid>
		<description>Even for rendering lists of objects, I prefer to keep the templates granular.  
&lt;pre lang=&quot;php&quot;&gt;
Template::render(&#039;user/details&#039;, $user);
&lt;/pre&gt;
I find this level of granularity helps encourage the maintenance of a single canonical template for each type of content.
&lt;pre lang=&quot;php&quot;&gt;
&lt;? if(!empty($photos)) { ?&gt;
&lt;ul class=&quot;objs photos&quot;&gt;
    &lt;? foreach($photos as $photo) { ?&gt;
    &lt;li&gt;&lt;?=Template::render(&#039;photo/thumb&#039;, $photo)?&gt;&lt;/li&gt;
    &lt;? } ?&gt;
&lt;/ul&gt;
&lt;? } ?&gt;
&lt;/pre&gt;
or
&lt;pre lang=&quot;php&quot;&gt;
&lt;? if(!empty($user-&gt;profile_photo)) { ?&gt;
&lt;?=Template::render(&#039;photo/thumb&#039;, $user-&gt;profile_photo)?&gt;
&lt;? } ?&gt;
&lt;/pre&gt;

I find there&#039;s a balance to be struck between autonomy and completeness.  I find that methods like renderAll tend to make me do things like put &lt;li&gt;&lt;/li&gt; inside a template which really only wants to render a photo thumbnail.  Adding &lt;li&gt;&lt;/li&gt; to photo/thumbnail ties the template to its context, violating its autonomy, keeping me from using it elsewhere.  Drawing precise boundaries to keep the code dry requires granular templates.  Unless renderAll() took some additional arguments like $before and $after for wrapping output of individual items, but that seems to open a whole can of worms to solve a problem that granular templates solves already.</description>
		<content:encoded><![CDATA[<p>Even for rendering lists of objects, I prefer to keep the templates granular.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Template<span class="sy0">::</span><span class="me2">render</span><span class="br0">&#40;</span><span class="st_h">'user/details'</span><span class="sy0">,</span> <span class="re0">$user</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>

<p>I find this level of granularity helps encourage the maintenance of a single canonical template for each type of content.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="sy1">&lt;?</span> <span class="kw1">if</span><span class="br0">&#40;</span><span class="sy0">!</span><span class="kw3">empty</span><span class="br0">&#40;</span><span class="re0">$photos</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="sy1">?&gt;</span>
&lt;ul class=&quot;objs photos&quot;&gt;
    <span class="sy1">&lt;?</span> <span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re0">$photos</span> <span class="kw1">as</span> <span class="re0">$photo</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="sy1">?&gt;</span>
    &lt;li&gt;<span class="sy1">&lt;?=</span>Template<span class="sy0">::</span><span class="me2">render</span><span class="br0">&#40;</span><span class="st_h">'photo/thumb'</span><span class="sy0">,</span> <span class="re0">$photo</span><span class="br0">&#41;</span><span class="sy1">?&gt;</span>&lt;/li&gt;
    <span class="sy1">&lt;?</span> <span class="br0">&#125;</span> <span class="sy1">?&gt;</span>
&lt;/ul&gt;
<span class="sy1">&lt;?</span> <span class="br0">&#125;</span> <span class="sy1">?&gt;</span></pre></div></div>

<p>or</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="sy1">&lt;?</span> <span class="kw1">if</span><span class="br0">&#40;</span><span class="sy0">!</span><span class="kw3">empty</span><span class="br0">&#40;</span><span class="re0">$user</span><span class="sy0">-&gt;</span><span class="me1">profile_photo</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="sy1">?&gt;</span>
<span class="sy1">&lt;?=</span>Template<span class="sy0">::</span><span class="me2">render</span><span class="br0">&#40;</span><span class="st_h">'photo/thumb'</span><span class="sy0">,</span> <span class="re0">$user</span><span class="sy0">-&gt;</span><span class="me1">profile_photo</span><span class="br0">&#41;</span><span class="sy1">?&gt;</span>
<span class="sy1">&lt;?</span> <span class="br0">&#125;</span> <span class="sy1">?&gt;</span></pre></div></div>

<p>I find there&#8217;s a balance to be struck between autonomy and completeness.  I find that methods like renderAll tend to make me do things like put &lt;li&gt;&lt;/li&gt; inside a template which really only wants to render a photo thumbnail.  Adding &lt;li&gt;&lt;/li&gt; to photo/thumbnail ties the template to its context, violating its autonomy, keeping me from using it elsewhere.  Drawing precise boundaries to keep the code dry requires granular templates.  Unless renderAll() took some additional arguments like $before and $after for wrapping output of individual items, but that seems to open a whole can of worms to solve a problem that granular templates solves already.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kris Jordan</title>
		<link>http://blog.kevburnsjr.com/simple-templating/comment-page-1#comment-1395</link>
		<dc:creator>Kris Jordan</dc:creator>
		<pubDate>Wed, 08 Apr 2009 23:03:05 +0000</pubDate>
		<guid isPermaLink="false">http://kevburnsjr.com/?p=222#comment-1395</guid>
		<description>Two more thoughts to bounce off of this post. 

One, should there be a check for an object passed in instead of an array? A common case in Recess is going to be passing an Object.

Two, supposing you&#039;re going to render a list of objects/arrays, would it be worth handling this case in the render? Or an alternative render like renderAll? Differences:

&lt;pre lang=&quot;php&quot;&gt;
$users = array( 
    array( &#039;name&#039; =&gt; &#039;A&#039;, &#039;userid&#039; =&gt; 1 ), 
    array( &#039;name&#039; =&gt; &#039;B&#039;, &#039;userid&#039; =&gt; 2 ) 
);

foreach ($users as $user) {
  Template::render(&#039;user/details&#039;, $user);
}
&lt;/pre&gt;
vs.
&lt;pre lang=&quot;php&quot;&gt;
Template::render(&#039;user/details&#039;, $users);
&lt;/pre&gt;
vs.
&lt;pre lang=&quot;php&quot;&gt;
Template::renderAll(&#039;user/details&#039;, $users);
&lt;/pre&gt;

The upside to keeping the loop within Template&#039;s logic instead of the view&#039;s logic is that the performance will be much better.</description>
		<content:encoded><![CDATA[<p>Two more thoughts to bounce off of this post. </p>
<p>One, should there be a check for an object passed in instead of an array? A common case in Recess is going to be passing an Object.</p>
<p>Two, supposing you&#8217;re going to render a list of objects/arrays, would it be worth handling this case in the render? Or an alternative render like renderAll? Differences:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="re0">$users</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span> 
    <span class="kw3">array</span><span class="br0">&#40;</span> <span class="st_h">'name'</span> <span class="sy0">=&gt;</span> <span class="st_h">'A'</span><span class="sy0">,</span> <span class="st_h">'userid'</span> <span class="sy0">=&gt;</span> <span class="nu0">1</span> <span class="br0">&#41;</span><span class="sy0">,</span> 
    <span class="kw3">array</span><span class="br0">&#40;</span> <span class="st_h">'name'</span> <span class="sy0">=&gt;</span> <span class="st_h">'B'</span><span class="sy0">,</span> <span class="st_h">'userid'</span> <span class="sy0">=&gt;</span> <span class="nu0">2</span> <span class="br0">&#41;</span> 
<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
<span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="re0">$users</span> <span class="kw1">as</span> <span class="re0">$user</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
  Template<span class="sy0">::</span><span class="me2">render</span><span class="br0">&#40;</span><span class="st_h">'user/details'</span><span class="sy0">,</span> <span class="re0">$user</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div></div>

<p>vs.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Template<span class="sy0">::</span><span class="me2">render</span><span class="br0">&#40;</span><span class="st_h">'user/details'</span><span class="sy0">,</span> <span class="re0">$users</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>

<p>vs.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Template<span class="sy0">::</span><span class="me2">renderAll</span><span class="br0">&#40;</span><span class="st_h">'user/details'</span><span class="sy0">,</span> <span class="re0">$users</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>

<p>The upside to keeping the loop within Template&#8217;s logic instead of the view&#8217;s logic is that the performance will be much better.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kris Jordan</title>
		<link>http://blog.kevburnsjr.com/simple-templating/comment-page-1#comment-1394</link>
		<dc:creator>Kris Jordan</dc:creator>
		<pubDate>Wed, 08 Apr 2009 22:45:18 +0000</pubDate>
		<guid isPermaLink="false">http://kevburnsjr.com/?p=222#comment-1394</guid>
		<description>Kev -

Great post. I&#039;ve just taken a stab at Layouts (a close relative to Templates) and will be using your technique for Templates.

One question I have regarding your example is if in greeting.tpl.php file, your manually declarations of $name = $d[&#039;name&#039;], and $userid are a best practice? Or if there is a reason for doing this over using PHP&#039;s extract()?

http://us3.php.net/manual/en/function.extract.php

You could change your Template.class.php to:
&lt;pre lang=&quot;php&quot;&gt;
// ...
ob_start();
extract($d);
include($file);
// ...
&lt;/pre&gt;

And then remove the chunk of PHP at the top of your template and arrive at the same functionality.

Good stuff!</description>
		<content:encoded><![CDATA[<p>Kev -</p>
<p>Great post. I&#8217;ve just taken a stab at Layouts (a close relative to Templates) and will be using your technique for Templates.</p>
<p>One question I have regarding your example is if in greeting.tpl.php file, your manually declarations of $name = $d['name'], and $userid are a best practice? Or if there is a reason for doing this over using PHP&#8217;s extract()?</p>
<p><a href="http://us3.php.net/manual/en/function.extract.php" rel="nofollow">http://us3.php.net/manual/en/function.extract.php</a></p>
<p>You could change your Template.class.php to:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="co1">// ...</span>
<span class="kw3">ob_start</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw3">extract</span><span class="br0">&#40;</span><span class="re0">$d</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw1">include</span><span class="br0">&#40;</span><span class="re0">$file</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="co1">// ...</span></pre></div></div>

<p>And then remove the chunk of PHP at the top of your template and arrive at the same functionality.</p>
<p>Good stuff!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

