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

Variable scape for include_php

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


Joined: 11 Nov 2003
Posts: 4
Location: Hamburg, Germany

PostPosted: Tue Nov 11, 2003 2:51 am    Post subject: Variable scape for include_php Reply with quote

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
View user's profile Send private message Visit poster's website
iolog
Smarty n00b


Joined: 08 Nov 2003
Posts: 4
Location: Ottawa

PostPosted: Tue Nov 11, 2003 4:43 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
kostik_y2k
Smarty n00b


Joined: 11 Nov 2003
Posts: 4
Location: Hamburg, Germany

PostPosted: Tue Nov 11, 2003 3:33 pm    Post subject: Reply with quote

Great, thank you!

That's what I've looked for Exclamation
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 -> General 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