lestrrat-p5 / Catalyst-View-Xslate

Text::Xslate View Class
Other
10 stars 8 forks source link

Additional path for templates #6

Open ghost opened 13 years ago

ghost commented 13 years ago

I want to set up a path for templates files in controller. In TT it's available over $c->stash->{'additional_template_paths'} = [...]; Is it available in Catalyst::View::Xslate? I think it's available when changing path => $self->path || [ $c->path_to('root') ], at your code to path => $self->path || [ $c->stash('additional_template_paths')] || [$c->path_to('root')],

May be other solution exists, let me know.

lestrrat commented 13 years ago

Thanks :)

If you're asking for a per-request thing, no C::V::Xslate doesn't do it, and until Text::Xslate changes, it never will. Unfortunately Text::Xslate as of today does not allow to change the path component.

If what you want is a per-request thing as above, under what circumstances would you need it?

ghost commented 13 years ago

O, ;( Bad...

I need to change path of templates according Host header, cause my Catalyst application is used for more than one sites at one time.

ghost commented 13 years ago

With TT it's easy (changing templates path per-request), but TT is very slow. :(

ghost commented 13 years ago

I've found a solution at #catalyst (thanks t0m):

In MyApp::View::Xslate

before process => sub { my ($self, $c) = @_; $self->path([$c->stash->('additional_template_paths')]) };

And it works perfectly. Could you add this solution to the POD? And for cache it will work too.

Also about POD improvement. What about adding: PACKAGE->config(expose_methods => [qw(foo)]); Because there is a missunderstanding how to set expose_methods in MyApp::View::Xslate.

lestrrat commented 13 years ago

Yeah, that works, but it completely takes away the performance gains that xslate offers, because it re-creates xslate object instance for each time you call that.

Xslate works best when used in a persistent environment, so that it can utilize its internal cache mechanism. see http://xslate.org/benchmark.html.

So no, I don't want to put it in the docs, as it gives the false impression that this can be done without much penalty :/

I don't really understand why you would need to change the settings for xslate for each request. However, if the configuration pattern is within a reasonable amount (i.e., you have may be a couple of paths that you want to switch between), then it might make more sense to implement MyApp::View::Xslate1 and MyApp::View::Xslate2 so you switch xslate instances depending on the request.

ghost commented 13 years ago

Good idea. How to switch depending on the request in the Catalyst? I don't know.

lestrrat commented 13 years ago

$c->forward('View::CustomView');