Created
December 12, 2013 16:41
-
-
Save b-abctech/7931035 to your computer and use it in GitHub Desktop.
Simple sample to create template plugins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this example based on module to do html/text truncate | |
# the Template plugin package | |
package Template::Plugin::TextTruncater; | |
use warnings; | |
use strict; | |
use utf8; | |
use DateTime; | |
use Moose; | |
use MooseX::NonMoose; | |
extends 'Template::Plugin'; | |
sub BUILDARGS { | |
} | |
sub truncater { | |
my ( $self ) = @_; | |
return sub { | |
my $text = shift; | |
return '-' unless $text; | |
return "message from plugin"; | |
}; | |
} | |
1; | |
# the in template just use and initial its | |
[% USE TextTruncater; %] | |
[% SET tc = TextTruncater.truncater(); %] | |
[% tc('my message') %] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment