Re: Smarty feature proposal: context aware template tags
| From: | Anders Janson | Date: | Wed, 28 Nov 2001 10:57:09 +0000 |
| Subject: | Re: Smarty feature proposal: context aware template tags | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-2068@lists.php.net to get a copy of this message | ||
Ivo Jansch wrote:
> Hello,
>
> I use a lot of custom functions and custom compiler functions in a
> Content Management System that I am building around Smarty. Now in some
> cases, I want tags to be 'context aware', by which I mean that tags
> should know that they are used 'inside' other tags.
> This kind of nesting happens when a tag needs to render a subtemplate,
> in which other tags could be used.
>
> I was thinking if it would be possible to keep some sort of 'tag stack'
> in which one can see what tags are currently being rendered.
>
> For example, if I have a tag named {foo} and the handler for this tag
> renders a template that contains a tag {bar}, than inside the handler
> function for {bar}, $smarty->m_tagstack should contain
> array("foo","bar");
I wish Smarty had custom start and end tags!! Then this suggestion would
really make sense!
We could , for example, write custom tags like "bar", which would only be
allowed to be used in a certain context, perhaps only within a {foo}...{/foo}
block. Or render different output, depending on the context (but would this
be good design?).
But today we only have a few tags where you could consider yourself "within"
the tag. The section tag perhaps being the best example, but I still wonder
why you would need to know this? Could you give a real-life example of a
situation where this would be useful ?
>
> Another case would be inside sections and includes. If there were for
> example a {foo} tag inside a {section} inside another {section} in an
> include, the stack would contain array("include", "section",
> "section",
> "foo");
Again, why or when would this be useful? I'm not saying it's bad, I'm just
saying I don't understand the need :-)
>
> Maybe the stack could also contain other information, like the arguments
> and properties.
Yeah. Makes sense.
>
>
> What do you think?
Personally, I see no use for it now ( $0.02, SEK 0.21, euro...??? ;-)
However, if we were given custom end tags... definitely YES!
/Anders