简体   繁体   中英

Smarty 3 assign variable in template

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM