0

We are using smarty,

In one of our views we have:

{if $header.showNav}...{/if}

and if we want to set that we use:

$header = $smarty->getTemplateVars('header');
$header['showNav'] = true;
$smarty->assign('header', $header);

Which works, But it seems rather long winded.

Does smarty provide a way to manage this easier?

Hailwood
  • 89,623
  • 107
  • 270
  • 423

1 Answers1

2

Why not just roll your own function:

function updateSmarty($smarty, $templateVar, $key, $value) {
    $templateVars = $smarty->getTemplateVars($templateVar);
    $templateVars[$key] = $value;
    $smarty->assign($templateVar, $templateVars);
}

Then you can one line it where you need it:

updateSmarty($smarty, 'header', 'showNav', true);

Or even:

function showNav($smarty) {
    updateSmarty($smarty, 'header', 'showNav', true);
}

Then:

showNav($smarty);
Petah
  • 45,477
  • 28
  • 157
  • 213
  • Yeah, That's what I was planning on doing, i just thought that smarty might have a built in way to do this! – Hailwood Sep 25 '12 at 00:52