Adding Extra Tags
$tt3 = Template3->new( tagset => [ picture => { type => 'replace', start => '<picture:', end => '>', replace => sub { my ($self, $text) = @_; # TODO: check image exists, add height and width, # lookup title, etc., in metadata file return qq{<img src="/images/pictures/$text">}; } } ] );
Example:
Blah blah some text <picture:hello.png> Blah blah more text
Thus Spake Andy:
You can disable any or all of the 4 default tags (either via config parameters
or the TAGS
control). You can also add your own tags
if 4 aren't enough for you. This example shows an additional tag being
defined that expands things like <picture:hello.png>
into a proper
<img ...>
tag. This tag is in addition to all the usual TT3 tags, so it's
effectively become a custom part of the template language. It would be
easy to extend this to lookup the image (throwing an error if it doesn't
exist), determine the width, height, and perhaps some metadata from a file or
database to add a title and/or alt attribute. The nice thing is that all of
this happens just once when the template is compiled so there's no runtime
overhead involved (you can also write code to do it at runtime if you prefer
but that's beyond the scope of this simple example).