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

how to get template vars from fetched template ?

 
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 -> Smarty 3
View previous topic :: View next topic  
Author Message
azrad
Smarty n00b


Joined: 20 Apr 2010
Posts: 4

PostPosted: Wed Apr 21, 2010 3:42 am    Post subject: how to get template vars from fetched template ? Reply with quote

Hi,

I've been searching Smarty forum for my problem solution.

Currently, my coding setup as follows:

index.tpl
Code:

{assign var=theme value="small"}

<p>Lorem ipsum...</p>


index.php
Code:

$smarty->assign('the_page', $smarty->fetch('index.tpl'));

$tpl_theme = $smarty->tpl_vars['theme']->value;

$theme = ($tpl_theme) ? $tpl_theme : 'default';

$smarty->display($theme .'.tpl');


and my theme file: small.tpl
Code:

...

<div id="content">{$the_page}</div>

...


my problem is, i cannot get the assigned value for var:theme.
im using the latest Smarty 3 beta 8 version.

anyone can help me?
Back to top
View user's profile Send private message
azrad
Smarty n00b


Joined: 20 Apr 2010
Posts: 4

PostPosted: Wed Apr 21, 2010 3:47 am    Post subject: it works well in Smarty2 Reply with quote

Previously, I've used this method in Smarty2 using $smarty->get_templat_vars('theme');

Now from Smarty3-b8 REAME file, it has the getTemplateVars() methods. I would assume this is as the same as in Smarty2.

So, from my code, I've changed the code abit:

index.php
Code:

$fetched_template = $smarty->feetch('index.tpl');
$theme = $smarty->getTemplateVars('theme');

$smarty->display($theme .'.tpl');


but it does not work. is there any workaround on this?
Back to top
View user's profile Send private message
azrad
Smarty n00b


Joined: 20 Apr 2010
Posts: 4

PostPosted: Wed Apr 21, 2010 4:13 am    Post subject: found in $smarty->utility Reply with quote

Hi, it's me again.

after done test to access $smarty->utility object, i've found the $tpl_vars object but don't know how to access it.

the hierarchy as follows:

- template_objects (array)
-- 2490750673 (object)
--- tpl_vars (array)
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Wed Apr 21, 2010 3:20 pm    Post subject: Reply with quote

Give the Smarty variable $theme a global scope by

index.tpl
Code:
{assign var=theme value="small" scope=global}


Then the following should work
Code:
$fetched_template = $smarty->feetch('index.tpl');
$theme = $smarty->getTemplateVars('theme');

$smarty->display($theme .'.tpl');
Back to top
View user's profile Send private message
azrad
Smarty n00b


Joined: 20 Apr 2010
Posts: 4

PostPosted: Thu Apr 22, 2010 3:05 am    Post subject: big thanks! Reply with quote

hi U.Tews

thanks for the tip, really appreciate it. and it works as you've said.

again thanks!
Back to top
View user's profile Send private message
m0nx
Smarty n00b


Joined: 08 Dec 2011
Posts: 2

PostPosted: Thu Dec 08, 2011 11:17 pm    Post subject: Reply with quote

hey... i'm sory but i have the same problem and i can not fix it:

i use smarty 3.1.6

file.tpl
Code:

   {assign var=SenderID value=$Nachricht.sender_id scope=global}
   {php} echo $smarty->getTemplateVars('SenderID'); {/php}



but the page could not be displayed...
if i delete the {php} line it works...

whats going wrong?[/code]
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Dec 09, 2011 3:19 pm    Post subject: Reply with quote

In 3.1.6 the {php} tag is not allowed, you have to use the SmartyBC class if you need that.
Back to top
View user's profile Send private message Visit poster's website
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 -> Smarty 3 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