nested template question
| From: | Ivo Jansch | Date: | Mon, 26 Mar 2001 12:26:39 +0000 |
| Subject: | nested template question | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-433@lists.php.net to get a copy of this message | ||
Hi,
I want to reuse some templates. For that purpose, I use the nested
template feature.
But I run into a problem with the names of my variables.
Suppose, I have a templated called item.tpl, with the following content:
<br><a href="{url}">{name}</a>
And this template is nested in some index.tpl:
<br>Your bookmarks:
{section name=outer loop=$yourbookmarks}
{include file="item.tpl"}
{/section}
<hr>
<br>My bookmarks:
{section name=outer loop=$mybookmarks}
{include file="item.tpl"}
{/section}
The problem is: This doesn't work. For it to work, item.tpl should be:
<br><a href="{$yourbookmarks/url}">{$yourbookmarks/name}</a>
But, as you can see, then item.tpl is not usable anymore for the
mybookmarks loop.
It's solvable by making an index.tpl like this:
<br>Your bookmarks:
{section name=outer loop=$yourbookmarks}
{include file="item.tpl" name=$yourbookmarks/name
url=$yourbookmarks/url}
{/section}
<hr>
<br>My bookmarks:
{section name=outer loop=$mybookmarks}
{include file="item.tpl" name=$mybookmarks/name url=$mybookmarks/url}
{/section}
But I'm not happy with this approach for two reasons:
- The {include } line gets big for large templates
- index.tpl is dependent on item.tpl. I can't add a field to item.tpl
without adding it to the
include line.
So my question is: is it possible to pass all variables of a section to
an included template, making it appear to the included template as if
the variables were 'local' to that template? (in other words, making it
work as in my first example)
I don't know if you understand my point, but I don't know how to explain
it more simple. :)
Greetings,
Ivo
--
Ivo Jansch <ivo@ibuildings.nl>
ibuildings.nl BV - information technology
http://www.ibuildings.nl