|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
kostik_y2k Smarty n00b
Joined: 11 Nov 2003 Posts: 4 Location: Hamburg, Germany
|
Posted: Tue Nov 11, 2003 2:51 am Post subject: Variable scape for include_php |
|
|
Hi,
I'm new to smarty and so I have my first problem here. I need my variables to be visible in the files included with include_php. Is there a way to do this?
Ex.:
Code: |
index.php
=======
$smarty->assign('var', 'test');
$smarty->display('index.html');
index.html
=======
{include file="modul.php"}
modul.php
=======
echo $var; // Not visible!
|
Thank you for any help! |
|
Back to top |
|
iolog Smarty n00b
Joined: 08 Nov 2003 Posts: 4 Location: Ottawa
|
Posted: Tue Nov 11, 2003 4:43 am Post subject: |
|
|
Two things,
First, you probably want to use include_php to include your 'modul.php' file, as it used to, well, include php files. Using 'include' calls the Smarty parser on the 'file' -- probably not the behaviour you want.
Second, you can access smarty variables using the get_template_vars() method.
Eg, modify modul.php:
Code: | // index.php
$smarty->assign('var', 'test');
$smarty->display('index.html');
// module.php
echo $this->get_template_vars('var');
//index.html
{include_php file=modul.php}
|
* note that when php files executed through include_php function, Smarty is exposed as '$this'
http://smarty.php.net/manual/en/language.function.include.php.php
http://smarty.php.net/manual/en/api.get.template.vars.php
-mark
--------------------------------------
Mark Priatel
Iolog Web Communications
www.iolog.com |
|
Back to top |
|
kostik_y2k Smarty n00b
Joined: 11 Nov 2003 Posts: 4 Location: Hamburg, Germany
|
Posted: Tue Nov 11, 2003 3:33 pm Post subject: |
|
|
Great, thank you!
That's what I've looked for |
|
Back to top |
|
|
|
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
|