This example shows Template::Toolkit's plugins (available from CPAN).

This demo is not Dancer ot bootstrap specific - it just shows how easy it is to use Template::Toolkit plugins.




Code Highlights

  • The minimal Dancer code is in ./lib/examples/template_plugins.pm .
  • This HTML tempate is in ./views/examples/template_plugins.tt .
  • To use Template::Plugin::* modules, install them using sudo cpan, then put a [% USE PLUGIN %] in your template file.
  • For the purpose of this demo, each [% USE PLUGIN %] is wrapped with a TRY/CATCH block, just in case the module is not installed. In a production website, you will probably have the module installed as a pre-requisite, and so the TRY/CATCH won't be needed

Template::Plugins::* Modules


Number::Format

Template::Plugin::Number::Format
  • Unformatted number: 1234567890
  • with format_number(): 1,234,567,890
  • with format_picture(): USD 1,234,567,890
  • with format_bytes(): 1.15G
  • with format_bytes(precision=>0): 1G

Image

Template::Plugin::Image
Image:
width: 33
height: 54
type: image/png

DataRandom

Template::Plugin::DataRandom
  • Random words: unimportant,partiality
  • Random characters: P,l,G,e,w
  • Random time: 03:56:33
  • Random date: 2003-11-29

xkcd

Template::Plugin::xkcd

Today's XKCD comic

Oops
Template::Plugin::xkcd failed to load:
undef error - Can't fetch http://xkcd.com/info.0.json: Internal Exception at /opt/perl-5.14.2/lib/site_perl/5.14.2/Template/Plugin/xkcd.pm line 24.