Smarter Parsing with Smarty

by
Annika Backstrom
in Uncategorized on 10 August 2008. #Web#PHP#Programming#smarty

My day job makes heavy use of Smarty for page templating. We're currently moving away from XTemplate, which I generally don't like, but it does have one nice feature: curly braces in CSS and JavaScript blocks aren't interpreted as template tags. I set out to determine if this behavior could be easily applied to Smarty.

The Problem

By default, Smarty uses curly braces to denote template tags, ie. {foreach from=$widgets item=widget}. The left and right tag delimiter are configurable, defaulting to { and }, respectively. Whitespace is allowed after the left delimiter. This means the following CSS rule is interpreted as a Smarty tag: