php - Dynamic variable names in Smarty -


I want to use some variable dynamically assigned to PHP in Smarty, here's an example:

  $ content_name = 'body' $ smarty- & gt; Assign ('content_name', $ content_name); $ Smarty- & gt; Allocated ($ CONTENT_NAME. '_ Title', $ title); $ Smarty- & gt; Allocated ($ CONTENT_NAME.'_ body ', $ body); // fixed value // $ content_name = home // $ home_title = $ title // $ home_body = $ body  

The reason I want to use these dynamically because I have many versions Calling a task that includes the code above, they all use the same template and therefore do not want to use only $ heading, $ body because their value will conflict with each other.

Given that I know that I want to use title and body variables based on set content_name, how can I achieve this in a sensible way? According to my comment on using an array instead of dynamic variable, here is an example of how to add war to the head:

/ P>

php:

  $ vars = array (); Whatever the function () {global $ Wars; $ Vars [] = array ('first name' => gt; 'mike', 'nickname' = & gt; 'smith'); } $ Smarty- & gt; Assign ('wars', $ Wars); {$ Vars [loop] First name} {$ vars [loop]  

smarty:

  {section name = loop loop = $ vars} Name: {$ vars [loop] .surname} {/ section}  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -