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: alliteration,endowment
  • Random characters: E,v,n,z,r
  • Random time: 07:01:05
  • Random date: 2003-12-09

xkcd

Template::Plugin::xkcd

Today's XKCD comic

That's very exciting! The bad news is that it's a risk factor for a lot of things.