Smarty – How to assign a variable into a variable in the template

Recently I needed to assign several variables into one smarty variable inside the template.

Here is the basic rules for the example:

  • You have a text that says “Your registration expires in # days”;
  • You want The text “in # days” to change to “today” if the # days is 0.

Here’s a way you can do this with smarty variables inside the template (whether you should do this in the template is not a discussion for this post).

The key here is that when you want to include a variable as part of the value of another variable you need to use value=”$in_days. Notice the ` before and after the variable name inside the double quotes. You can use this method to include variables inside value statements anywhere in smarty templates and make modifications of those included variables.

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Leave a Reply

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