[Catalyst] Catalyst, ExtJS and TT
Bill Moseley
moseley at hank.org
Mon Mar 18 13:54:21 GMT 2013
On Mon, Mar 18, 2013 at 3:56 AM, Dave Howorth <dhoworth at mrc-lmb.cam.ac.uk>w=
rote:
> >
> > 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) =3D @_;
> >
> > $c->stash->{template} =3D 'EntrepriseWindow.js.tt';
> >
> > $c->response->content_type('application/javascript');
> >
> > }
> >
> > I cannot write this ?
> >
> > $c->stash->{template} =3D '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 ) =3D @_;
my $template =3D $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
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20130318/0b424=
d66/attachment.htm
More information about the Catalyst
mailing list