GeorgeNava edited this page Jul 16, 2011 · 8 revisions
Clone this wiki locally

Template formatters

Templates come with a powerful feature called 'formatters' or 'filters' which help us present data in a more readable way, like using date formats, uppercase, time ago, etc. Here are some default filters that come with app.go, you can customize them and add more filters as you please:

upper    : changes text to UPPERCASE
lower    : changes text to lowercase
title    : changes text to TitleCase
break    : changes new lines for html breaks
unbreak  : changes html breaks for new lines
plural   : pluralize some text if a number is different than one
ellipsis : truncates a word and adds html ellipsis if longer than 40
date     : presents date in 2001/12/31 format
time     : presents time in 2001/12/31 23:59:59 format
now      : shows current datetime in 2001/12/31 23:59:59 format
today    : shows current date in 2001/12/31 format
year     : shows current year, good for Copyright {@|year} MyCorp.
ago      : elapsed time in days/hours/mins and seconds
decimal  : shows float numbers with two decimals only
money    : shows float numbers with dollar sign and two decimals
pointer  : dereferences pointer to value
html     : default html formatter

Usage: {myvar|myfilter} {Name|title} {Posted|ago} {Balance|money} {@|now}

Note: there will be changes coming to the template package, we may update this module soon after the package goes public.