View previous topic :: View next topic |
Author |
Message |
azrad Smarty n00b
Joined: 20 Apr 2010 Posts: 4
|
Posted: Wed Apr 21, 2010 3:42 am Post subject: how to get template vars from fetched template ? |
|
|
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 |
|
azrad Smarty n00b
Joined: 20 Apr 2010 Posts: 4
|
Posted: Wed Apr 21, 2010 3:47 am Post subject: it works well in Smarty2 |
|
|
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 |
|
azrad Smarty n00b
Joined: 20 Apr 2010 Posts: 4
|
Posted: Wed Apr 21, 2010 4:13 am Post subject: found in $smarty->utility |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Apr 21, 2010 3:20 pm Post subject: |
|
|
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 |
|
azrad Smarty n00b
Joined: 20 Apr 2010 Posts: 4
|
Posted: Thu Apr 22, 2010 3:05 am Post subject: big thanks! |
|
|
hi U.Tews
thanks for the tip, really appreciate it. and it works as you've said.
again thanks! |
|
Back to top |
|
m0nx Smarty n00b
Joined: 08 Dec 2011 Posts: 2
|
Posted: Thu Dec 08, 2011 11:17 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Dec 09, 2011 3:19 pm Post subject: |
|
|
In 3.1.6 the {php} tag is not allowed, you have to use the SmartyBC class if you need that. |
|
Back to top |
|
|