0

Having a bit of a problem. Trying to assign a template variable within a smarty 3 template file but it just doesnt seem to register it.

I know I can use this in the controller:

$this->data['myVar'] = 'something';

Dont want to use that. I have tried this:

{assign var="myVar" value="something" noache}

But for some reason it just doesnt seem to work.

The template this is being used in is extending another template.

I have tried setting the variable scope to global.

The other weird thing is even if i try and assign a variable which is then just being outputted just below, it still returns empty as if the assign method is broken all together. No errors though.

I know some might consider it bad practise to assign in smarty but my reasoning for this is it would allow me to specify my meta info in the template. This means when carrying out any meta tweaks they can be done in the template rather than someone going into my controllers.

Hope someone can shed some light,

Thanks for reading.

fl3x7
  • 3,723
  • 6
  • 26
  • 37
  • You can just create your own plugin for smarty that will store in its instance or static variable. – meze Apr 22 '12 at 01:16

1 Answers1

-2

Not sure why the problem occured but instead ended up using the Smarty 3 {block}{/block} tags as I was extending a master template anyway. This created the desired functionality.

Hope this helps someone else.

fl3x7
  • 3,723
  • 6
  • 26
  • 37
  • Left this answer quite some time ago and since stopped using smarty in favour of Laravels blade syntax. If someone's going to down vote nearly 2 years later at least leave a comment or a better answer :) – fl3x7 Feb 22 '14 at 17:03