Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Dedicated server web hosting provided by Guru-host.eu.
initcap modifier

 
Post new topic   Reply to topic    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
bimal
Smarty Elite


Joined: 19 Apr 2007
Posts: 419
Location: Kathmandu, Nepal

PostPosted: Sat Nov 21, 2009 12:43 am    Post subject: initcap modifier Reply with quote

When we assume, that a name is stored in lowercase, a small modifier can fix the display. (This is a info only post.) Save the file: modifier.initcap.php into your plugins folder as:

modifier.initcap.php
Code:
/**
* Capitalizes all first letters in a word.
*/
function smarty_modifier_initcap($string='')
{
   $string = ucwords($string);
   return($string);
}


And usage example:
Code:
{$name|initcap}


Now, it can look like SQL's INITCAP() function. You can extend this modifier to extra process and validate the name, like removing extra spaces, etc.

However, a very quick and lazy processing does not need a separate modifier. You can call php's function directly, as:
Code:
{$name|ucwords}

_________________
Skype: pbimal
To hire instantly as a freelancer - https://www.odesk.com/o/profiles/users/_~~657b70cc7f2c616a/
Visit my website - http://bimal.org.np/ for more articles
800+ screenshots to learn about website mistakes: http://mistakes.sanjaal.com/
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    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