Help - Search - Members - Calendar
Full Version: Automatic Title Case
Movable Type Community Forum > Additional Resources > Tips and Tricks
btrott
There are global tag attributes for lower case and upper case, but none for first-letter-of-each-word-case. We could add one, but in the meantime you might want to see if there is a CSS declaration you could use for text-transform.
buhlogged
You could add this to Util.pm at lib/Mt/:

CODE
sub title_case {
   my($text) = @_;
   $text =~ tr!A-Z!a-z!;
   $text =~ s!^(\W*?)(\w)!$1.uc($2)!ge;
   $text =~ s!(\W)(\w)!$1.uc($2)!ge;
   $text =~ s!\b(i+v*)\b!uc($1)!gei;
   $text;
}


and add title_case to the @EXPORT_OK variables (line 14 or thereabouts). Save and upload.

Open Context.pm (at lib/MT/Template/) and add title_case to the use MT::Util variables (line 9). Then in sub post_process_handler add this:

CODE
           if ($args->{'title_case'}) {
               $str = title_case($str);
           }


Save and upload.

So in your templates you do it like:

CODE
<$MTEntryTitle title_case="1"$>


This can also be useful for the MTAuthor tags.

Hope this helps.
Rebel Soul
Is there a way to automatically force the title of an entry into a Title Case with a tag?

Eg "ENTRY TITLE" to show as "Entry Title" ?

Reason: I'll be copying and pasting subjects a lot and it would be handy if this was automatic so I don't have to edit the case each time to fit in with the other posts.

Thanks.  :)
kadyellebee
Easiest CSS way to do this is add the following to the .title class :
CODE
text-transform : capitalize;


smile.gif
Kristine
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.