template-toolkit

How can I force list context in Template Toolkit with RDBO?

I have a TT plugin that does the trivial unique ids: sub get_unique_uid_tt { my ( $classname, $o ) = @_; my %h; foreach my $item ( @{$o} ) { unless ( exists $h{ $item->id } ) { $h{ $item->id } = 1; } } return keys %h; } where the template call is simply: [% Namespace.get_unique_uid_tt( data.users ) %] and...

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 typing out the array. ...

Bugzilla templates: what's the difference between [% and [%+

Code in Bugzilla templates is usually delimited by [% and %]. But sometimes I see [%+ and [%-. Can someone explain the difference or point me at suitable documentation? Google has failed me on this occasion. For example: [%- event.value.subject FILTER html %] or [%+ END %] ...

Is there a way to compare two variables in Template Toolkit?

[% IF OrgType.id == Organization.org_type_id %]selected="selected"[% END %] Does not work even when they both evaluate to the same number. [% IF OrgType.id == 3 %]selected="selected"[% END %] (i.e. hard-coding in a number for testing purposes) does work. [% OrgType.id %] and [% Organization.org_type_id %] both print "3" on t...

How can I handle hash keys containing illegal identifier characters in Template Toolkit?

In Template Toolkit, if I have the following variable containing a hashref: [% artist = { 'life-span' => '1975 to 1987', } %] What is the best way to output the data in 'life-span'? I have tried... [% artist.life-span %] ^This fails because of the hyphen. [% artist.'life-span' %] ^This fails because the syntax is in...

How can I use a filter as a method in template toolkit?

I am trying to use the truncate filter on 2 variables (rsstitle and rssdescription), and assign the truncated version to a new variable (rsstitletrunc and rssdescriptiontrunc). I am relatively new to Template Toolkit, and dont understand why this code wont work (the SETs and IF/ELSE/END): [% FOREACH feed IN rss_feeds %] <div class="rss...

Syntax hightlighting of template-toolkit within Ultraedit

Have anyone succesfully created a "wordfile" that works? I've tried but i can't get it to highlight [% and %] ...

Adding a submode to nXhtml

Having made the jump just recently from XEmacs to GNU Emacs, I'm really loving nXhtml mode for writing web code. I'd like to be able to add a sub mode to it, though, and I'm not sure how. There doesn't seem to be a good reference to do so. I have a mode for Perl's Template Toolkit, loaded as tt-mode and the default for .tmpl files, an...

Get Template::Plugin::Date to accept MySQL dates as well as datetimes

I'm using the date plugin for Template::Toolkit (Template::Plugin::Date), it works well with datetimes (yyyy-mm-dd hh:mm:ss) pulled straight out of MySQL, but it will not work with dates (yyyy-mm-dd). What's the simplest way to get date.format to accept dates (without modifying the sql query)? Thanks. ...

How can I get elements out of an array with Template Toolkit?

I have an array of Paths which i want to read out with Template Toolkit. How can I access the array Elements of this array? The Situation is this: my @dirs; opendir(DIR,'./directory/') || die $!; @dirs = readdir(DIR); close DIR; $vars->{'Tree'} = @dirs; Then I call the Template Page like this: $template->process('create.tmpl', $vars)...

How can I switch timezones in Perl's Template::Plugin::Date?

I have a calendar on my website, generated in Perl using Template::Toolkit and Template::Plugin::Date. It highlights the current day. I achieve this by iterating through all the dates (as I print the calendar) and comparing against the current date. Something like this: [% IF cur_date == date.format(format = '%Y-%m-%d') %] ... [% END ...

How do I eliminate TT's "Wide character in print" warning ?

I have this warning every time I run my CGI-script (output is rendered by Template::Toolkit): Wide character in print at /usr/local/lib/perl5/site_perl/5.8.9/mach/Template.pm line 163. What's the right way to eliminate it? I create the tt object using this config: my %config = ( ENCODING => 'utf8', INCLUDE_PATH...

How can I handle template dependencies in Template Toolkit?

My static web pages are built from a huge bunch of templates which are inter-included using Template Toolkit's "import" and "include", so page.html looks like this: [% INCLUDE top %] [% IMPORT middle %] Then top might have even more files included. I have very many of these files, and they have to be run through to create the web pag...

How can I write a Template.pm filter to generate PNG output from LaTeX source code?

I am looking for a way of generating PNG images of equations from LATEX source code embedded in templates. For example, given: [% FILTER latex_display ] \begin{eqnarray*} \max && U(x,y) \\ \mathrm{s.t.} && p_x x + p_y y \leq I \\ && x \geq 0, y \geq 0 \end{eqnarray*} [% END %] I would like to get the output: <div class="latex display...

Syntax hightlighting of template toolkit files in Aptana/Eclipse

Does anyone know how I can add syntax highlighting to Eclipse/Aptana for Template Toolkit files? All I need is for [% ... %] to be a different colour. ...

So, I have this jquery bit that adds a row to a table the way I need it to, but it's UGLY

I have a table that looks like this: <table name="exercises" id="workout-table"> <tr> <th>Name</th> <th>Reps/Intervals</th> <th>Sets</th> <th>Weight/Distance/Time</th> </tr> [%- i=0 %] [% WHILE i<=10 %] <tr class="workout-rows"> <td><input type="text" name="workout[exercise][[% i %]][name]" /></td> <td><input type="text" name="workou...

How can I track down "Template process failed: undef error" in Perl's Template Toolkit?

I've moved a Perl CGI app from one web host to another. Everything's running fine except for Template Tookit which is giving the following error: "Template process failed: undef error - This shouldn't happen at /usr/lib/perl5/5.8.8/CGI/Carp.pm line 314." The templates are working fine on the other web host. I've set the DEBUG_ALL flag ...

Why doesn't die $template->error() show a line number?

In the following short program: use Template; my $template = Template->new (INCLUDE_PATH => "."); $template->process ("non-existent-file") or die $template->error (); why doesn't die produce a line number and newline? My output looks like this: ~ 502 $ perl template.pl file error - non-existent-file: not found ~ 503 $ ...

Escape Single Quotes in Template Toolkit

Do you ever escape single quotes in template toolkit for necessary javascript handlers? If so, how do you do it. [% SET s = "A'B'C" %] <a href="/abc.html" onclick="popup('[% s | html_entity %]')">ABC</a> html_entity obviously doesn't work because it only handles the double quote. So how do you do it? ...

AJAX: how to get progress feedback in web apps, and to avoid timeouts on long requests?

This is a general design question about how to make a web application that will receive a large amount of uploaded data, process it, and return a result, all without the dreaded spinning beach-ball for 5 minutes or a possible HTTP timeout. Here's the requirements: make a web form where you can upload a CSV file containing a list of UR...