Smarty is a template engine for PHP that facilitates a managable way to separate application logic and content from its presentation. This is mostly used in industrial architecture following MVC (Model View Controller) architecture. The application data that contain no information about how they will be presented. They are passed into Smarty by the application, then the template designer edits the templates and uses a combination of HTML tags and template tags to format the presentation of these elements. Smarty ensures programmer can make changes to the application logic without the need to restructure templates, and the template designer can make changes to templates without breaking application logic.

Smarty is used in *.tpl files. These tpl files can use web presentation technologies like HTML and Javascript. While working recently in a web page rendered by Smarty while using the code , It threw the following error

The specific message was: Syntax Error in template “/websites/site.local/views/manager/index.tpl” on line 564 “onclick : function() {” – Unexpected ” : “, expected one of: “}”

Now this error might look a bit weird, since you can easily access variables passed from PHP code using {variableName}

However, while using smarty variables inside a javascript, the Javascript code should be enclosed using the {literal}{/literal} tag if you haven’t. This prevents Smarty from parsing what’s in between so that the Javascript code is not being mistaken for PHP code.

So the code can look like :



Smarty is a neat way to separate your code. I am still learning it and enjoying working over it. If you have nay questions regarding SMARTY you can ask by commenting here… More about Smarty:

Leave a Reply

Your email address will not be published. Required fields are marked *