Brainstorms of a Webdev

Web development, PHP, Security, etc… etc…

  • Home
  • About

23

Apr

Template Lite Modifiers

Posted by tarnus  Published in PHP, Template Lite

One of the greatest tools I have in my library set is Template Lite . Template lite is a light-weight version of another template engine known as Smarty. Once you start using template lite you will be pleasantly surprised by how powerful yet modular it is.

My whole point of this blog is to talk about modifiers. A modifier enables you to pass some php modifying code into a template lite variable.

Example:


{$mytlitevariable|ucfirst }
//This would capitalize the first letter of the variable.

What doesn't work

It is important to note that you cannot necessarily use this on all modify type php functions. Some php functions do not pass the main variable into the first option.

Using str_replace would not work as the passed variable is the third option in the command. {$mytlitevariable|str_replace:black:brown }
//is the equivalent to
str_replace($mytlitevariable,"black","brown")
//which will not work. You will have to use it via php:
{php} echo str_replace("black","brown",$mytlitevariable) {/php}

Modifiers Stacking

Modifier stacking allows you to make multiple changes to a variable by passing multiple modifiers to the template lite variable.

Example: {$myvar|ucfirst|truncate:40:"..."}

Creating your own Modifiers

Don't be afraid to create your own modifiers. When ever I run into something that I can't do I add it into template lite.
//Example: This is the source code for the indent modifier.
//Once you create the modifier and save it in the plugins folder with the name
//modifier.indent.php.
{$myvar|indent}
//Note there are 2 extra arguments you can use with it as well.

function tpl_modifier_indent($string,$chars=4,$char=" ")
{
return preg_replace('!^!m',str_repeat($char,$chars),$string);
}

This is the start of my experimentation with blogs. I am constantly forgetting how to do things with template lite and other things. I plan on adding these tips and tricks to my blog so I have one place to search for the info. Feel free to comment as I realize I don't know it all but am willing to share my experiences along the way.


Continue reading...

no comment

Search

Get Support

Categories

  • Domain Names (1)
  • Electronics (1)
  • Javascript (1)
  • mysql (1)
  • PHP (4)
  • Template Lite (2)
  • Uncategorized (1)

Archives

  • May 2008
  • April 2008

Blogroll

  • Alien Assault Traders
  • Diana Botsford
  • Oznet
  • Sonnar Internet
  • Springfield Net

RSS Twitter: tarnus

  • Oh...waiting always sucks when your busy 09:05:17 AM May 23, 2008 from txt
  • Why do people refuse to listen 04:00:34 PM May 19, 2008 from im
  • Back to work... its a Monday 10:51:08 AM May 19, 2008 from im
  • Nothing like kids with nothing better to do than mess with my servers to ruin my sleep 12:52:10 AM May 18, 2008 from im
  • I got to get in better shape...I hate feelin winded 05:23:05 PM May 17, 2008 from txt

Meta

  • Register
  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
April 2008
M T W T F S S
    May »
 123456
78910111213
14151617181920
21222324252627
282930  

Recent Post

  • sql file splitter to the rescue
  • Palm Centro, my new phone
  • PHP day count and date comparison
  • Experiments in Domain Parking
  • Javascript Auto Focus Form Element
  • Variable Variables and Template Lite
  • Template Lite Modifiers

Recent Comments

  • Online Reviews » Blog Archive… in Palm Centro, my new phone
© 2007 Brainstorms of a Webdev
Theme by Wired Studios, courtesy of Corvette Garage
Valid XHTML | Valid CSS 3.0
Powered by Wordpress