I have been using template toolkit for extending an existing domain specific language(verilog) for over 3 years now. While overall I am happy with it, the major irritant is that when there is a syntax/undef error the error message does not contain the correct line number information to debug the error.
e.g. I would get a message indicating "0 is not defined" since I would be using [%x.0%] and similar constructs at multiple locations in the file figuring out which line has the problem becomes difficult.
TT3 seems to be under development indefinitely
My question to the gurus is is there a better alternative to TT. My requirements are
I can only recommend Text::Xslate here. It is better than TT in every way and beats out most of the competition as well. And lastly, it fits all your requirements. Literally. All of them.
It is even proven in practice, as it is used by one of the Top 100 websites worldwide and one of the Top 10 websites in Japan: Livedoor
Xslate in comparison to TT:
Two things to note for your special case:
syntax => 'TTerse'
to the constructor to get a syntax that's designed to be as close to TT as possible.type => 'text'
to the constructor to disable html_escape
interpolation.I'm currently experimenting with Template::Alloy and it seems to be, by and large, a drop-in replacement for TT. Template::Alloy::TT lists the differences between TT and Alloy, most of which are of the form "This works/is allowed in Alloy, but not in TT." Addressing your specific issue, the list includes:
- Alloy has better line information
When debug dirs is on, directives on different lines separated by colons show the line they are on rather than a general line range.
Parse errors actually know what line and character they occured at.
Mojolicious comes with its own templating system Mojo::Template. Its lightweight and can be used even outside of the mojolicious system. Here is an example from the docs:
use Mojo::Template;
my $mt = Mojo::Template->new;
# Simple
my $output = $mt->render(<<'EOF');
% use Time::Piece;
<!DOCTYPE html>
<html>
<head><title>Simple</title></head>
% my $now = localtime;
<body>Time: <%= $now->hms %></body>
</html>
EOF
say $output;
and another
# More advanced
my $output = $mt->render(<<'EOF', 23, 'foo bar');
% my ($number, $text) = @_;
%= 5 * 5
<!DOCTYPE html>
<html>
<head><title>More advanced</title></head>
<body>
test 123
foo <% my $i = $number + 2; %>
% for (1 .. 23) {
* some text <%= $i++ %>
% }
</body>
</html>
EOF
say $output;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With