|
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 |
dango Smarty n00b
Joined: 07 Jul 2004 Posts: 4
|
Posted: Wed Jul 07, 2004 11:11 am Post subject: How do I pass a variable from a template to php? |
|
|
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 |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
|
Back to top |
|
dango Smarty n00b
Joined: 07 Jul 2004 Posts: 4
|
Posted: Wed Jul 07, 2004 3:52 pm Post subject: boots, thanks alot. but I still have a small problem : |
|
|
How do I assign them from the template to the PHP ?
thanks again! |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Jul 07, 2004 3:56 pm Post subject: |
|
|
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 |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Jul 07, 2004 3:57 pm Post subject: |
|
|
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 |
|
dango Smarty n00b
Joined: 07 Jul 2004 Posts: 4
|
Posted: Wed Jul 07, 2004 4:12 pm Post subject: thank you both for your answer |
|
|
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
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 |
|
|
|
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
|