|
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 |
Archytas Smarty Rookie
Joined: 07 Jul 2004 Posts: 15 Location: The Netherlands
|
Posted: Wed Jul 28, 2004 11:47 am Post subject: template inside another template |
|
|
Hi,
I made a php file to display a template. The php file gets contents from the database and assigns them to the smarty object so it is available to the template file. Since the template filename is coming from the database as well, I can show any template referenced in the database when I refence it's object number. (ex. get_object.php?id=2)
Now, my designer makes the templates for each object and wants to include some templates into other ones (like a poll and a menu inside a page.tpl). She can't just include {include file="poll.tpl"} because the poll won't know it's options (there are more than one poll and the variables are not assigned for it). But like the other object I can get them through my php file get_object?id=3 (if object 3 is the poll that I want to include). I can get each file seperately by I can't include them inside other objects.
I tried the following in my page template:
Code: | {include file="header.tpl"}
{include file="bierflesje.tpl"}
komt ie
{include_php file="get_object.php" id="2"}
al wat gezien?
{php}
include($_SERVER['DOCUMENT_ROOT'].'/get_object.php?id=2');
{/php}
{include file="footer.tpl"} |
The first include ({include_php}) does not pass $id=2 since it can't find the object. The second include in php style throws a fatal error:
Failed opening '/home/httpd/w3c.org/httpdocs/get_object.php?id=2' for inclusion.
How can I make an easy way for my designer to include other objects?
All help is welcome! |
|
Back to top |
|
webadept Smarty Regular
Joined: 09 Mar 2004 Posts: 41
|
Posted: Wed Jul 28, 2004 12:52 pm Post subject: |
|
|
I know I'm one of those that are always thinking things are obvious, when in fact he doesn't really understand the whole problem but.. .if your designer knows the id of the page she wants to put things in, and she knows the file names of the sub included files that she wants to put in the page, then... can't she simply use the config file to do that? If she has a config file that is
Code: |
[1]
poll = poll2.tpl
menu = menu4.tpl
sidemenu = sidmenu8.tpl
[2]
poll = poll2.tpl
menu = menu4.tpl
sidemenu = sidmenu8.tpl
[3]
poll = poll5.tpl
menu = menu4.tpl
sidemenu = sidmenu8.tpl
# no poll on this page #
[4]
poll =
menu = menu4.tpl
sidemenu = sidmenu8.tpl
|
Again, probably too simple but .. should work with couple of {IF} statments in there, and you won't have to change a thing, except perhaps pass the id of the page you are calling so she can get the right section of the config, but i'll bet you are already doing that anyway.
If you have these numbers in some sort of set she can define for areas of your website, she could uses sets of numbers to find a single section as well that covers multiple pages.
webadept |
|
Back to top |
|
apz Smarty Rookie
Joined: 07 Aug 2004 Posts: 6 Location: iran - yazd
|
Posted: Mon Aug 09, 2004 6:03 am Post subject: a problem !!!! |
|
|
Code: | {include file="header.tpl"}
{include file="bierflesje.tpl"}
komt ie
{include_php file="get_object.php" id="2"}
al wat gezien?
{php}
include($_SERVER['DOCUMENT_ROOT'].'/get_object.php?id=2');
{/php}
{include file="footer.tpl"} |
when use this code in a tple file ...
when you refresh page by F5 or CTRL+F5 the content of page be damaged !!!
see the result !
now press CTRL+F5 in smarty forum and see the page be damaged .
this problem is very important ,
we must solve this .
help anyone . |
|
Back to top |
|
Archytas Smarty Rookie
Joined: 07 Jul 2004 Posts: 15 Location: The Netherlands
|
Posted: Tue Aug 17, 2004 11:57 pm Post subject: |
|
|
I still can't find out why the parameter is not readable in the included php file.
When I use
{include_php file="get_object.php" id="2"}
And echo the $id in the php file it is not assigned to be 2. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Aug 18, 2004 12:47 am Post subject: |
|
|
I could be wrong, but I believe that unlike {include}, {include_php} does not accept parameter attributes.
Quote: | How can I make an easy way for my designer to include other objects?
All help is welcome! |
Resources: http://smarty.php.net/manual/en/plugins.resources.php
You can encapsulate all of the logic needed to fetch a template from a custom handler using resources. For example, you might create a resource called go (get_object) and then you would do the template include like this:
Code: | {include file="go:2"} |
Your resource would be responsible for doing all of the hard work of decoding the request and fetching the template from your custom handler. In essence, this gives you a hook into the template retrieval process and hides implementation details from the templates. Indeed, as a general rule, I would strongly advise not using {include_php} (or {php}) in templates. |
|
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
|