Re: nested template question
| From: | Jonas Bengtsson | Date: | Thu, 01 Jan 1970 00:00:00 +0000 |
| Subject: | Re: nested template question | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-434@lists.php.net to get a copy of this message | ||
have you tried to pass vaiables with your include?
Example (from manual):
{include file=footer.tpl title="Main Menu table_bgcolor="#c0c0c0"}
/Jonas
On Mon, 26 Mar 2001, Ivo Jansch wrote:
> 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
>
> ---
> You are currently subscribed to smarty as: pt99jbn@hubble.rby.hk-r.se
> To unsubscribe send a blank email to $subst('Email.Unsub')
> Visit Smarty's homepage at
> http://www.phpinsider.com/php/code/Smarty/
>