Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

parse functions/modifiers in function attributes

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
themightychris
Smarty Rookie


Joined: 02 Jan 2005
Posts: 6
Location: Bucks County, Pennsylvania, US

PostPosted: Sun Jan 02, 2005 10:48 pm    Post subject: parse functions/modifiers in function attributes Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun Jan 02, 2005 11:31 pm    Post subject: Reply with quote

Isn't this cleaner?

Code:
<select name=location>
  {html_options options=$options selected=$location|default:"someplace"}
</select>
Back to top
View user's profile Send private message
themightychris
Smarty Rookie


Joined: 02 Jan 2005
Posts: 6
Location: Bucks County, Pennsylvania, US

PostPosted: Mon Jan 03, 2005 12:09 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
themightychris
Smarty Rookie


Joined: 02 Jan 2005
Posts: 6
Location: Bucks County, Pennsylvania, US

PostPosted: Sun Apr 03, 2005 11:19 pm    Post subject: Reply with quote

still would be nice to be able to run functions for arguements. Using {capture} is ugly
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
kills
Smarty Elite


Joined: 28 May 2004
Posts: 493

PostPosted: Mon Apr 04, 2005 6:39 am    Post subject: Reply with quote

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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Mon Apr 04, 2005 9:26 am    Post subject: Reply with quote

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
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Mon Apr 04, 2005 9:27 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
themightychris
Smarty Rookie


Joined: 02 Jan 2005
Posts: 6
Location: Bucks County, Pennsylvania, US

PostPosted: Thu Apr 07, 2005 4:06 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu Apr 07, 2005 10:57 am    Post subject: Reply with quote

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 Smile

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP