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

modifiers.capitalize

 
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 -> Plugins
View previous topic :: View next topic  
Author Message
walovaton
Smarty n00b


Joined: 17 Jul 2003
Posts: 1
Location: Cali, Colombia

PostPosted: Thu Jul 17, 2003 9:13 pm    Post subject: modifiers.capitalize Reply with quote

Hello there,

I was looking at the Smarty code and I just saw that the plugin 'modifier.capitalize.php' needs a little correction.

ucwords() needs to recieve a string in lower case... so, if you send an upper case string the function won't work as expected. (see the manual)

The solution here is to nest strtolower() into ucwords()... somthing like this:
ucwords(strtolower($string))

Is this little fix in CVS??... I hope it can make it into the next release.

See you,


-William
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
messju
Administrator


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

PostPosted: Thu Jul 17, 2003 9:56 pm    Post subject: Reply with quote

maybe not a bad idea to me but there may be loads of templates out there, that rely on the behavior you call "unexpected".
"unexpected" is always a bit subjective due to different expectations by different parties.

every php-function can be used as a modifier, which means that {$var|capitalize} is quite the same as {$var|ucfirst}. the only difference is, that the former even works with $smarty->security=true and the latter needs to be put in a whitelist-array ($smarty->security_settings['MODIFIER_FUNCS']) to be allowed to be called even with $smarty->security=true (which is not default, but a nice thing to have)

this means you can achieve the behaviour you suggest by using {$var|strtolower|capitalize}

on the other hand slight: different semantics (the ones suggested by you) would justify the different name ("capitalize" vs. "ucfirst"), besides the fact, that "capitalize" sounds more ...umm... "human"(?) than "ucfirst" does. so we'll end up in two options ("capitalize" and "ucfirst") that do slight different things which does not sound bad to me.

i'd be interested in other opinions out there Smile
Back to top
View user's profile Send private message Send e-mail Visit poster's website
boots
Administrator


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

PostPosted: Thu Jul 17, 2003 11:01 pm    Post subject: Reply with quote

Not a huge fan of these modifiers (capitalize, lower, upper) to begin with since CSS already provides the text-transform attribute (none | capitalize | uppercase | lowercase). On the other-hand, there is an expectation to meet here and IMHO the obvious thing is do what the term implies in Smarty and not follow the underlying PHP implementation--precisely as walovaton suggests.

Messju's point is well taken, so I propose a comprimise and a slightly new direction:

1) leave the existing modifiers as-is for BC;
2) create a new modifier called text-transform (where did I hear that before?) which takes as its only parameter one of: (none | capitalize | uppercase | lowercase). The new modifier would have the (ahem) expected behaviour.

Failing that, I would probably just go ahead and break the BC--apparently, there are a lot of special cases that need to be dealt with when using ucwords and it seems that this is precisely the sort of thing that Smarty plugins should be doing for template users.

2c.
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 -> Plugins 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