Usually, all data should be ready for display by the time it hits a smarty template, as it’s a presentation layer. However, from time to time, there is a need to perform tasks on the data before you display it. For example, if you are pulling product data from a database and assigning it straight to the page without any processing. Thankfully, Smarty makes a lot of these things relatively easy – such as string replacement.

String replacement in PHP is done via the str_replace() function – taking a needle and haystack.

Smarty works very much the same, except for it’s function call which is piped on to the end.

Image Credit: chefranden