{assign var="num" value=42} $smarty->assign('num', $num); $smarty->display('example.tpl'); // Get value of num variable $num_value = $smarty->getTemplateVars('num'); echo $num_value; // Output: 42
$smarty->assign('num', 42); $smarty->assign('name', 'John Doe'); $smarty->display('example.tpl'); // Get all assigned variables $template_vars = $smarty->getTemplateVars(); foreach ($template_vars as $name => $value) { echo $name . ': ' . $value . 'This example assigns two variables to the template, "num" and "name". It then displays the template and retrieves all assigned template variables using the getTemplateVars function. The function returns an associative array of variable names and their values, which are displayed on the webpage. Package Library: Smarty
'; } // Output: num: 42
name: John Doe