I’m building a site at the moment that uses the Smarty templating engine and I came across a snag today. The global “Smarty” variable includes a nice $Smarty.post reference where by you can get posted variables to display in your template.

For example, if you have an input with the name of “firstname”, you could populate it with the posted item if you so wished. Like this:

This is great if you have static input names.

From time to time though, you might be constructing your input names, like this:

I do this quite often for certain scenarios so that I know that the id can then be stripped off and processed correctly in the controller / processing function with PHP in the back end.

Something like the following doesn’t work in Smarty:

Instead you need to assign a new variable to be name you want, and then use that instead, like so:

Image Credit: Jef Safi, 'pictosophizing