Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Assigning when using template functions doesn't work

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
pitbull82
Smarty Rookie


Joined: 01 Feb 2006
Posts: 18
Location: Poland

PostPosted: Sat Mar 26, 2011 5:27 pm    Post subject: Assigning when using template functions doesn't work Reply with quote

Hello

I suppose that I found a bug. It's hard to say it in one word so I prepared very simple project to test and analyse - you may download it from http://www.mnabialek.pl/download/testsmarty.zip

into libs folder you have to upload content of Smarty libs folder.

In my opinion intended result is generating "testmenu" on output but:

a) when using Smarty 3.0.7 I get notice that variable is not set
b) when using Smarty 3.0.0 I get blank page
c) when using Smarty 2.6.26 I get "testmenu" on output - that's correct behaviour in my opinion

The strangest thing is that when in Menu.php file you change

Code:
return $this->page->get('menu.tpl');


into

Code:
return $this->page->fetch('menu.tpl');


it will work fine but I have to use custom method to fetch template.

Please check this issue because I would like to know if it's really a bug and if would be fixed or maybe I'm doing something wrong.

Best regards
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun Mar 27, 2011 10:13 am    Post subject: Reply with quote

This is not a bug but result of the extended scoping of Smarty 3.

Your assign in method generate() of the Menu class will assign the variable 'menue' in the local scope of the template index.

Your $this->page->get('menu.tpl') does use the Smarty object as root for known variables. For that reasion it does not see the variable 'menu'.

$this->page->fetch('menu.tpl') does call fetch in the context of the template object $page (of index.tpl) and for that reasion does see 'menu'.

Simplest solution is to assign 'menu' in global scope
Code:
$this->page->assignGlobal('menu','testmenu');
Back to top
View user's profile Send private message
pitbull82
Smarty Rookie


Joined: 01 Feb 2006
Posts: 18
Location: Poland

PostPosted: Sun Mar 27, 2011 6:49 pm    Post subject: Reply with quote

Thanks. Ok, I understand now it's not a bug. So in that case wouldn't be useful to add also appendGlobal method ?
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP