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

[Résolu] Transit des variables au travers des includes

 
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 -> Language: French
View previous topic :: View next topic  
Author Message
Shadwolf
Smarty n00b


Joined: 01 Nov 2010
Posts: 2

PostPosted: Mon Nov 01, 2010 5:19 pm    Post subject: [Résolu] Transit des variables au travers des includes Reply with quote

Bonjour,

Je suis en train de réaliser un petit site pour me familiariser avec Smarty et je découpe mon index au travers de plusieurs templates qui sont inclus dans mon index.tpl.

Dans mon index.php je défini un objet $template = new Smarty().

Je souhaiterai dans mes includes rajouter des données comme par exemple :
$template->assign('var', 2) afin de pouvoir les utiliser dans picture.tpl par exemple, qui est inclus dans mon index.tpl.

Cependant cela ne semble pas marcher.

Comment faire pour utiliser smarty dans différents fichiers ?
- Doit-on créer un objet Smarty par page PHP ?
- Doit-on créer un seul objet Smarty dans index.php et le faire transiter dans les includes ?

Merci à ceux qui pourront me répondre.

Shad.


Last edited by Shadwolf on Mon Nov 01, 2010 9:53 pm; edited 1 time in total
Back to top
View user's profile Send private message
Gowser
Smarty Pro


Joined: 19 Feb 2008
Posts: 104
Location: Nantes (France)

PostPosted: Mon Nov 01, 2010 8:11 pm    Post subject: Reply with quote

Si je comprend bien, ton soucis est que t'es variables ne sont pas passée d'un tpl à un autre (qui s'incluent) ?

Tu peux faire transiter tes variables d'un tpl à un autre en les assignant dans la déclaration de l'include :
Code:

// je veux faire passer ma variable $foo dans mon include afin qu'elle soit interprétable :
{include file='mon_template.tpl' foo=$foo}

// ou meme lui changer de nom
{include file='mon_template.tpl' bar=$foo}


http://www.smarty.net/manual/fr/language.function.include.php


++


Last edited by Gowser on Mon Nov 01, 2010 11:04 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
Shadwolf
Smarty n00b


Joined: 01 Nov 2010
Posts: 2

PostPosted: Mon Nov 01, 2010 9:53 pm    Post subject: Reply with quote

Merci !

Problème réglé
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 -> Language: French 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