Questions tagged [template-toolkit]

The Template Toolkit is a fast, flexible and, highly extensible template processing system for Perl. There are also Python and JavaScript implementations.

The Template Toolkit is a fast, flexible and highly extensible template processing system. It is Free (in both senses: free beer and free speech), Open Source software and runs on virtually every modern operating system known to man. It is mature, reliable and well documented, and is used to generate content for countless web sites ranging from the very small to the very large.

It is written in the Perl programming language but you don't need to know any Perl to use it. In fact, it was specifically created to allow web designers and developers to concentrate on generating web pages without getting bogged down in programming matters. We call this a "Clear Separation of Concerns" and it makes the whole processes of building, updating and maintaining a web site or web application significantly easier.

References:

266 questions
7
votes
2 answers

Template Toolkit, test for last iteration in a nested loop

I'm using template toolkit to form a simple JSON response (see the code below). I need to put a comma after all elements of the response except the last. I believe I need to make use of TTs iterator, however I'm not getting it right. With this code,…
mark
  • 1,769
  • 3
  • 19
  • 38
7
votes
1 answer

Mojolicious::Lite with Template Toolkit

I'm trying to get Template Toolkit to work as the default renderer in Mojolicious::Lite. What I have: use strict; use warnings; use Mojolicious::Lite; use Mojolicious::Plugin::TtRenderer; plugin tt_renderer => { template_options => { INCLUDE_PATH…
friedo
  • 65,762
  • 16
  • 114
  • 184
7
votes
3 answers

Calling outside subs and modules in Template Toolkit without Plugins?

I am trying to call an outside Perl module in a Template Toolkit .tt file. The module I want to use is Util, and I want to call Util::prettify_date. I was able to include this module using Template Toolkit's plugin interface: I set up the load, new,…
Sam Lee
  • 7,049
  • 10
  • 42
  • 47
6
votes
3 answers

I get extra CR using TT (perl template toolkit)

I use perl v5.10 (on windows 7) + TT v2.22. When I use TT, for each source line, I get in the produced html an extra CR : Source text (windows format): "Some_html" CR LF Output text : "Some_html" CR CR LF However, when I convert my…
gerard
  • 1,923
  • 1
  • 12
  • 14
6
votes
5 answers

Template-Toolkit and complex variables

Say I'm working in Perl using Catalyst. I assign an array of hashes to a a variable, ie: my @array = ($some_hash); $c->stash->{foo}->{bar} = \@array; How do I select an element from $some_hash, such as 'id', in Template Toolkit? In Perl I can…
danwoods
  • 4,889
  • 11
  • 62
  • 90
6
votes
2 answers

How do I get a random number in template toolkit?

I want to get a random number using template toolkit. It doesn't have to be particularly random. How do I do it?
Sam Lee
  • 9,913
  • 15
  • 48
  • 56
6
votes
3 answers

how to reverse an anonymous list in template toolkit?

Is it possible to reverse an anonymous list in template toolkit? e.g. [% FOREACH month IN [1..12].reverse %] [% month %] [% END %] (except that doesn't work). Just wondered if there was a neat way to do it without using variables or explicitly…
aidan
  • 9,310
  • 8
  • 68
  • 82
6
votes
3 answers

Less verbose debug screen in Catalyst?

in my stage server I would like to activate the debug so the clients can find errors for themselves before the app goes to the production server. BUT I only want the first part of the message, not the Request, or the Session Data. For example:…
Nacho B
  • 1,573
  • 1
  • 12
  • 16
6
votes
1 answer

How to get element from array in Template-Toolkit?

[% a = ['one', 'two', 'four'] %] [% a.1 %] # it prints two. OK! But when I want this: [% a = ['one', 'two', 'four'] %] [% n = 1 %] [% a.n %] # it doesn't work How can I use var n in order to get defined element from array?
edem
  • 3,222
  • 3
  • 19
  • 45
6
votes
1 answer

Catalyst Template::Toolkit render output

I'm using Catalyst with Template::Toolkit as my templating system. I would like to be able to render specific parts of templates and then have them returned to me so I can store them in a variable. The Template::Toolkit documentation mentions that…
srchulo
  • 5,143
  • 4
  • 43
  • 72
6
votes
1 answer

Template Toolkit and lazy Moose attributes - how to make them behave?

If I declare lazy attribute in perl class using Moose, and the attribute is using builder: has 'colors' => ( is => 'rw', isa => 'ArrayRef', lazy => 1, builder => '_build_colors', ); then in Template::Toolkit template I'll try to use this…
Sly
  • 415
  • 2
  • 8
5
votes
1 answer

How can I throw a warning in Template::Toolkits CATCH block?

The code I am working on has a bunch of TRY/CATCH blocks in Template::Toolkit templates. They look like this: [% TRY; x = OBJ.method(data); CATCH; ""; END %] This is bad from two perspectives. First, the error is being…
Chas. Owens
  • 64,182
  • 22
  • 135
  • 226
5
votes
1 answer

Template Toolkit: how return a hash from a MACRO BLOCK

Is it possible to write macros or blocks that return a hash to the caller? I tried to modularize some template code: [%- MACRO MakeSomeThing(something) BLOCK; s = { a => 'a', b => something, c => 'c' }; # RETURN s; #…
vlad_tepesch
  • 6,681
  • 1
  • 38
  • 80
5
votes
2 answers

Can I easily add new directives to Template Toolkit for Perl?

I'd like to add my own directives to Template Toolkit instead if adding functions and/or virtual methods via the plugin system. Is this easily doable without delving too deep into Template::Grammar? And are there any examples I could study on CPAN?
Richard Simões
  • 12,401
  • 6
  • 41
  • 50
5
votes
1 answer

How do I configure Dancer2 and Template Toolkit to use a different Stash module

How would I modify the default configuration of Template Toolkit in a Dancer2 site to make use of Template::Stash::AutoEscaping?
Cebjyre
  • 6,552
  • 3
  • 32
  • 57
1
2
3
17 18