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

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
cam
Smarty Rookie


Joined: 17 Jul 2003
Posts: 9
Location: France, Grenoble

PostPosted: Fri Jul 18, 2003 7:26 am    Post subject: include_php Reply with quote

hello,

I have a real problem with include_php. I'd like to use it in my template like this :

In the template : ajouter.tpl :

{include_php file="ajouter.php"}
<HTML code ...>

In the Php file : ajouter.php :

require("../../libs/Smarty.class.php");
$smarty = new Smarty;
$smarty->assign('var',$var);

I want to use the variable $var in my template (ajouter.tpl), but I don't want to print it. So I don't use :

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

The problem is that I can't receive the value of $var in the templates.
Is a function existe for the php file for giving the variable $var to the templates ajouter.tpl ?
Because, $var is always null in the temlpates

Thank you very much


Last edited by cam on Wed May 05, 2010 10:42 pm; edited 1 time in total
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Fri Jul 18, 2003 7:44 am    Post subject: Reply with quote

You needn't create a new instance of smarty -- you can use $this. See here: http://www.phpinsider.com/smarty-forum/viewtopic.php?t=127&highlight=includephp
Back to top
View user's profile Send private message
cam
Smarty Rookie


Joined: 17 Jul 2003
Posts: 9
Location: France, Grenoble

PostPosted: Fri Jul 18, 2003 7:52 am    Post subject: Reply with quote

Thank you for your quickly answer. It will realy help me.

But I don't anderstand $this.

Thanks


Last edited by cam on Wed May 05, 2010 10:42 pm; edited 1 time in total
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Fri Jul 18, 2003 7:56 am    Post subject: Reply with quote

My bad--I should have used a link that at least pointed to the appropriate man page. The relevant quote in the documentation is:
Quote:
The smarty object is available as $this within the PHP script that you include.


That means that instead of having to create a new instance of smarty (in your example, $smarty) you have access to the current instance of smarty via the $this variable.

eg.

$this->assign('var',$var);

HTH
Back to top
View user's profile Send private message
cam
Smarty Rookie


Joined: 17 Jul 2003
Posts: 9
Location: France, Grenoble

PostPosted: Fri Jul 18, 2003 7:59 am    Post subject: Reply with quote

Than you, this is more clear.
Sorry for my english that is not very good !!


Last edited by cam on Wed May 05, 2010 10:42 pm; edited 1 time in total
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Fri Jul 18, 2003 8:00 am    Post subject: Reply with quote

maybe read this: http://php.net/manual/en/language.oop.php as a starter.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Fri Jul 18, 2003 8:03 am    Post subject: Reply with quote

I read you fine Smile

Still, you will probably prefer the manual page in french Wink

bon chance!
Back to top
View user's profile Send private message
cam
Smarty Rookie


Joined: 17 Jul 2003
Posts: 9
Location: France, Grenoble

PostPosted: Fri Jul 18, 2003 8:03 am    Post subject: Reply with quote

Thank you too.
I have a lot of progress to do !
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 -> 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