<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>sixohthree.com &#187; smarty</title>
	<atom:link href="http://sixohthree.com/tag/smarty/feed" rel="self" type="application/rss+xml" />
	<link>http://sixohthree.com</link>
	<description>The Weblog of Adam Backstrom</description>
	<lastBuildDate>Sat, 04 Feb 2012 12:27:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Smarter Parsing with Smarty</title>
		<link>http://sixohthree.com/512/smarter-parsing-with-smarty</link>
		<comments>http://sixohthree.com/512/smarter-parsing-with-smarty#comments</comments>
		<pubDate>Sun, 10 Aug 2008 21:07:53 +0000</pubDate>
		<dc:creator>Adam Backstrom</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[smarty]]></category>

		<guid isPermaLink="false">http://blogs.bwerp.net/?p=512</guid>
		<description><![CDATA[Don't gobble my markup.]]></description>
			<content:encoded><![CDATA[<p>My day job makes heavy use of <a href="http://www.smarty.net/">Smarty</a> for page templating. We&#8217;re currently moving away from <a href="http://www.phpxtemplate.org/HomePage">XTemplate</a>, which I generally don&#8217;t like, but it does have one nice feature: curly braces in CSS and JavaScript blocks aren&#8217;t interpreted as template tags. I set out to determine if this behavior could be easily applied to Smarty.</p>
<h3>The Problem</h3>
<p>By default, Smarty uses curly braces to denote template tags, ie. <code>{foreach from=$widgets item=widget}</code>. The left and right tag delimiter are configurable, defaulting to <code>{</code> and <code>}</code>, respectively. Whitespace is allowed after the left delimiter. This means the following CSS rule is interpreted as a Smarty tag:</p>
<pre><code>&lt;style type="text/css"&gt;
body { font-size: 80%; }
&lt;/script&gt;</code></pre>
<p>This would generate an error, claiming &#8220;syntax error: unrecognized tag: font-size: 80%.&#8221; You can use the <a href="/~adam/2008/08/10/literal.txt"><code>{literal}</code> tag</a> to escape a block of text, or <a href="/~adam/2008/08/10/ldelim.txt">use <code>{ldelim}</code></a> instead of &#8220;{&#8220;, or <a href="/~adam/2008/08/10/custom-delim.txt">change the delimiter</a> to something less common like <code>&lt;!--{</code>. I would prefer the XTemplate behavior.</p>
<h3>The Solution</h3>
<p>Here is <a href="/~adam/wp-uploads/2008/08/smarty-tag-whitespace.patch">a patch</a> that modifies Smarty to ignore left delimiters which are immediately followed by whitespace. <code>{foreach}</code> would be parsed, but <code>{ foreach}</code> would not. This has potential security implications since an errant space could expose part of your template to the world, but it has the potential to simplify some very convoluted markup.</p>
<p>I&#8217;ve done some <a href="/~adam/2008/08/10/testing.txt">limited testing</a> (including creating a one-character template tag) and it seems to work fine. I&#8217;ll have to try with some more complicated templates, but hopefully this will make its way into our Smarty as a custom mod. (Thankfully we deploy Smarty via Subversion, so it&#8217;s relatively easy to mod the local library install.)</p>
]]></content:encoded>
			<wfw:commentRss>http://sixohthree.com/512/smarter-parsing-with-smarty/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

