Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

How do I pass a variable from a template to php?

 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
dango
Smarty n00b


Joined: 07 Jul 2004
Posts: 4

PostPosted: Wed Jul 07, 2004 11:11 am    Post subject: How do I pass a variable from a template to php? Reply with quote

Hi,

I am new to smarty.
Sometimes I have to use include_php from a template.

How can I pass a variable from the template to the php?

I know how to get the data back, with $this->assign
but, If I can't pass data to the function, I have to get 1 include file
per function, since I can't tell the include file which function I
need exactly...

thanks,

Dan.
Back to top
View user's profile Send private message MSN Messenger
boots
Administrator


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

PostPosted: Wed Jul 07, 2004 3:12 pm    Post subject: Reply with quote

http://smarty.php.net/manual/en/api.get.template.vars.php

(but use $this instead of $smarty)
Back to top
View user's profile Send private message
dango
Smarty n00b


Joined: 07 Jul 2004
Posts: 4

PostPosted: Wed Jul 07, 2004 3:52 pm    Post subject: boots, thanks alot. but I still have a small problem : Reply with quote

How do I assign them from the template to the PHP ?

Very Happy

thanks again!
Back to top
View user's profile Send private message MSN Messenger
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Jul 07, 2004 3:56 pm    Post subject: Reply with quote

What are these include_php functions for? Maybe this could be handled easier with plugin functions, so instead of:

{include_php file="my.php"}

You would have:

{my foo=$foo bar=$bar}

Then your parameters are readily available to your function.
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


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

PostPosted: Wed Jul 07, 2004 3:57 pm    Post subject: Reply with quote

hmm. {assign} ?

The thing is, you're going about this a little back-asswards. Templates are data consumers, not producers. In general you never want to use {php} or {include_php} blocks in your template. Instead, use plugins and do your data setup from your controller scripts.
Back to top
View user's profile Send private message
dango
Smarty n00b


Joined: 07 Jul 2004
Posts: 4

PostPosted: Wed Jul 07, 2004 4:12 pm    Post subject: thank you both for your answer Reply with quote

The thing is I have very little time to finish my work,
and I didn't have time to try and understand how the plugin
thing works Sad

the reason why I have templates that generate data is :

assume I have 4 tables, that have the same structure,
but the data inside is different foreach of them

so I call them from my main template (which is called from php file) :

{include file="8.tpl"}

and I want to have context X inside the template

{include file="8.tpl"}

but this time I want to have content Y inside

so I need to tell 8.tpl to show content X
and then show content Y
and I need to get this content from a database,

this is why I was thinking to :

include_php file from 8.tpl and tell it I need content X
then include_php file again from 8.tpl and tell it content Y this time

and then 8.tpl will call the php and ask for the right content.

So I understand from your answers I am messing things up , am I ?

I will be more than happy to hear if you have a better solution ?

thanks in advance for your time,

Dan.
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development 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