template-toolkit

Why can't I use Template Toolkit?

I am trying to use TemplateToolkit instead of good ole' variable interpolation and my server is giving me a lot of grief. Here are the errors I am getting: *** 'D:\Inetpub\gic\source\extjs_source.plx' error message at: 2008/09/30 15:27:37 failed to create context: failed to create context: failed to load Template/Stash/XS.pm: Couldn't ...

How can I profile template performance in Template::Toolkit?

What's the best method for benchmarking the performance of my various templates when using Template::Toolkit? I want something that will break down how much cpu/system time is spent processing each block or template file, exclusive of the time spent processing other templates within. Devel::DProf, for example, is useless for this, sin...

How can I use Template Toolkit on a string instead of a file?

I have some strings that I am pulling out of a database and I would like to use Template Toolkit on them, but I can't seem to figure out how to use strings as TT input. Any tips? Thanks! -fREW ...

How do I reference a scalar in a hash reference in Perl?

Simple question: How do I do this on one line: my $foo = $bar->{baz}; fizz(\$foo); I've tried \$bar->{baz}, \${$bar->{baz}}, and numerous others. Is this even possible? -fREW Update: Ok, the hashref is coming from DBI and I am passing the scalar ref into template toolkit. I guess now that I look more closely the issue is somethin...

How do I use multiple Template Toolkit TTSite views on a Catalyst site?

I use Template Toolkit to generate views of pages in Catalyst. To do some basic Ajax, I want to have some output pages not use the TTSite style, but a much more basic structure. Do I put something special into the stash to use a .tt2 file without the header/footer/etc that automatically comes with the rest of my templates? (site gener...

What's the right way to display a DBIx::Class ResultSet in my Catalyst project that uses Template Toolkit?

Given a DBIx::Class resultset, for example: my $rs = $c->model("DB::Card")->search({family_name => "Smith"}); the tutorials I've read use the stash to pass an arrayref of rows: $c->stash->{cards} = [$rs->all]; This results in the query getting executed at this point, and the resulting objects stuffed into the stash, so they can be ...

Can Perl's Template Toolkit warn on undefined values?

Is there a way to make Perl's Template display warnings for all undefined values that I attempt to use the GET directive on (via [% %]) during Template::process? The default behavior is to ignore and move on. I'd like to warn only in the case of undefined values, if possible, and to log messages to STDERR. ...

Can I redirect output from TPAGE

I want tpage to redirect the output to a different file. The redirect filter seems almost to do what I want but when I use it I get : redirect error - OUTPUT_PATH is not set Can I set OUTPUT_PATH using tpage? ...

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? ...

Is there a Catalyst tutorial that uses HTML::Template instead of TT?

I've been looking through a couple of Catalyst tutorials and they all tend to use Template Toolkit instead of HTML::Template. I've spent a lot of time with HTML::Template and I like it, and while I can see the power of TT, I don't know it, and I feel like I'd be learning two things at once; plus, because it does its processing in-templa...

How can I define constants in a Template Tookit template in a Catalyst app?

I want to use a constant in my TT template. In HTML::Mason (my previous templating engine of choice) I could do: <%once> use MyApp::Constants qw(CONSTANT); </%once> How can I do this in Template Toolkit? As mentioned in the title this is a Catalyst app so I was thinking I could put the constants in the stash but that seems a bit awkwa...

Where can I find 'more advanced web toolkit' for Template Toolkit?

I really like Template Toolkit and like how it works with Catalyst, but I would like more 'web advanced' toolkit. It could be just a package of *.tt files for Web objects like these: Selector, Selector_DateTime, Menu, Data_Table... Is there something like that somewhere on the Web? If not, why not? ...

Which Perl session management library works well with TemplateToolkit?

I've considered CGI::Application and CGI::Session. Of the two, CGI::Session seems more promising. CGI::Application model, however, doesn't look like it would work well with Template Toolkit. (Am I wrong to think so?) I would like to evaluate more session management libraries, before comitting to one. Any recommendations? I'm looking for...

How can I render only a specific `BLOCK` in a Perl's Template Toolkit?

How can I render only a specific BLOCK in a template? Suppose I have this BLOCK in text.tt, a Template Toolkit file: [% BLOCK someblock %] some block test blah blah blah [% END %] I want to be able to use process() to handle just that portion: $tt->process("text.tt/someblock", {...}, {...}); Is this the right way to handle this? ...

Calling outside 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, and error function (as described here: http://template-toolkit.org/docs/modules/Template/...

Should my MVC controllers be object-oriented?

I'm making a Perl website, and I'll using Template Toolkit (for the view), a whole bunch of objects for DB interaction and business logic (the model), but I'm wondering: should the controllers be OO? I feel like they should, just for consistency, but it also feels it might be a bit redundant when I'm not interacting with the controllers...

Why can't my Catalyst application read my Template Toolkit files?

I am trying to get the Catalyst framework to work using Template Toolkit, and I'm having issues with Template::Provider. I've isolated the issue to calls to stat. In Template::Provider::_init, calls to stat work correctly, however in other functions calls to stat return []. It seems like Template::Provider is doing some weird caching stu...

How can you pass undef as an argument to an object method from a TT template?

Template-Toolkit seems to want to always interpolate undef to the empty string. So a template like this: Result is [% some_object.some_method (1, undef, 2) %] or this: Result is [% ttvar %] [% some_object.some_method (1, ttvar, 2) %] produces a call to Perl like: some_object->some_method (1, '', 2) when what I want is:...

Line numbers with template toolkit

I am using the Perl Template Toolkit to generate C files. I dearly want to be able to include #line directives in my C code so that error messages from the C compiler send me to the right place (the template file) rather than the wrong place (the template output). However, I don't know how to do this. The only result I got from Google w...

Using Perl's Template.pm, how can I select a random element from an array and output it?

Suppose I have the following in my template: [%- pages = [ 'one', 'two', 'three' ] -%] <p>Go to page [%- ... -%]</p> Assuming EVAL_PERL is not set (i.e., I cannot use a [%- PERL -%] block), what do I need to put inside the [%- ... -%] above so as to get the following output? <p>Go to page "a randomly picked element of pages"</p> ...