On Mon, Mar 18, 2013 at 3:56 AM, Dave Howorth <dhowo...@mrc-lmb.cam.ac.uk>wrote:
> > > > I have a javascript file named EntrepriseWindow.js in root dir. It > > contains some TT code. I must add a extension (I renamed the file > > EntrepriseWindow.js) for it to work. Otherwise, it does not work : > > > > sub EntrepriseWindow :Path('EntrepriseWindow.js') { > > > > my ($self, $c) = @_; > > > > $c->stash->{template} = 'EntrepriseWindow.js.tt'; > > > > $c->response->content_type('application/javascript'); > > > > } > > > > I cannot write this ? > > > > $c->stash->{template} = 'EntrepriseWindow.js'; > > Most frameworks that use TT have a mechanism to find template source > files based on their extension. In the case of Catalyst, see > > > http://search.cpan.org/~jjnapiork/Catalyst-View-TT-0.41/lib/Catalyst/View/TT.pm#TEMPLATE_EXTENSION You should be able to specify the full template name via the stash. Here's the code: sub process { my ( $self, $c ) = @_; my $template = $c->stash->{template} || $c->action . $self->config->{TEMPLATE_EXTENSION}; If the template is explicit in the stash then TEMPLATE_EXTENSION should not come into use. > If you think about it, the file you want TT to process is *not* a .js > file, it's a file with some TT syntax in it that needs processing to > *become* a .js file. So it would be unhelpful if Catalyst tried to > TT-process real .js files and it's reasonable, IMHO, to have something > like a .js.tt extension. > In this case Jean-Marc said that EntrepriseWindow.js has some TT code added. I agree that it would be clearer if it had a different extension so that later someone does not mistaken it for a js file. But, a javascript file really should be served statically. Jean-Marc, what per-request changes are you making to that file? Something like setting strings based on the user's language preference for that request? I would think it would be better to serve it statically (with caching headers) and then serve any pre-request changes in the actual html response. Serving up different javascript files with the same name could lead to problems. -- Bill Moseley mose...@hank.org
_______________________________________________ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/