View previous topic :: View next topic |
Author |
Message |
themightychris Smarty Rookie
Joined: 02 Jan 2005 Posts: 6 Location: Bucks County, Pennsylvania, US
|
Posted: Sun Jan 02, 2005 10:48 pm Post subject: parse functions/modifiers in function attributes |
|
|
smarty should parse function and modifier calls for function attributes, for example:
Code: |
<select name=location>
{html_options options=$options selected={$location|default:"someplace"}}
</select>
|
this isn't exactly what im doing, but equivilent, and right now what i have to do is
Code: |
{capture assign=somevar}{$location|default:"someplace"}{/capture}
<select name=location>
{html_options options=$options selected=$somevar}
</select>
|
it works, but it would be much cleaner and i think it makes sense that attributes should support nested smarty code like this |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sun Jan 02, 2005 11:31 pm Post subject: |
|
|
Isn't this cleaner?
Code: | <select name=location>
{html_options options=$options selected=$location|default:"someplace"}
</select> |
|
|
Back to top |
|
themightychris Smarty Rookie
Joined: 02 Jan 2005 Posts: 6 Location: Bucks County, Pennsylvania, US
|
Posted: Mon Jan 03, 2005 12:09 am Post subject: |
|
|
Hmm i wasn't aware that worked. What I was trying to use was a function not a modifier
here is what i have right now:
Code: |
{capture assign=refill_join_bd_dd}{refill field=join_bd_dd}{/capture}
<select name="join_bd_dd" id="join_bd_dd">
<option value="">&&</option>
{html_options options=$day_list selected=$refill_join_bd_dd}
</select>
|
what i wanted to be able to do
Code: |
<select name="join_bd_dd" id="join_bd_dd">
<option value="">&&</option>
{html_options options=$day_list selected={refill field=join_bd_dd}}
</select>
|
refill is a custom function of mine that takes the name of a form field and looks for it in get and post and returns the value with a specified encoding (default htmlspecialchars) or if its undefined a default value (defaults blank)
if modifiers work i suppose i can convert it to a modifier but as a function it makes more sense (my templates need to be created/edited by non-programmers) |
|
Back to top |
|
themightychris Smarty Rookie
Joined: 02 Jan 2005 Posts: 6 Location: Bucks County, Pennsylvania, US
|
Posted: Sun Apr 03, 2005 11:19 pm Post subject: |
|
|
still would be nice to be able to run functions for arguements. Using {capture} is ugly |
|
Back to top |
|
kills Smarty Elite
Joined: 28 May 2004 Posts: 493
|
Posted: Mon Apr 04, 2005 6:39 am Post subject: |
|
|
themightychris wrote: | still would be nice to be able to run functions for arguements. Using {capture} is ugly |
What about adding a modifier which calls your function internally? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Mon Apr 04, 2005 9:26 am Post subject: |
|
|
I still see a modifier as the best choice here:
Code: | <select name="join_bd_dd" id="join_bd_dd">
<option value="">&&</option>
{html_options options=$day_list selected="join_bd_dd"|refill}
</select> |
or even:
Code: | {assign var=field value=join_bd_dd}
<select name="{$field}" id="{$field}">
<option value="">&&</option>
{html_options options=$day_list selected=$field|refill}
</select>
|
|
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon Apr 04, 2005 9:27 am Post subject: |
|
|
another common way is to give your function an optional assign attribute.
counter and math from the smarty distribution work that way. |
|
Back to top |
|
themightychris Smarty Rookie
Joined: 02 Jan 2005 Posts: 6 Location: Bucks County, Pennsylvania, US
|
Posted: Thu Apr 07, 2005 4:06 am Post subject: |
|
|
The modifier syntax though does not allow for varied and descriptive extra parameters. For example, the aforementioned example function refill has optional params default, checked, selected, and encoding. There is no easy way to make those all available through a modifier syntax, let alone a way that is simple for template designers to understand.
Using an assign parameter is a good solution though. I've already used that it in numerous other functions for my sites but never thought to use it for refill. I will impliment that, but I still think it would be nice for smarty to support nested function calls. But I'm guessing from the resistence to it that it would be more than a trivial matter to impliment :-/ .
Thanks to both of you for the great suggestions though and especially for this wonderful system. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Thu Apr 07, 2005 10:57 am Post subject: |
|
|
Ahh, yes, if you need to support multiple optional parameters, then a function is probably simpler than a modifier. I was just going on what I was shown
The main problem with supporting nested tags is the fact that Smarty is essentially a regex parser. Nesting of that sort is one thing that regex's simply can't do. It's actually a little worse than that: you can't embed a close-delimiter in a tag, even in a string. (ie: {foo var="}"} will fail.) |
|
Back to top |
|
|