Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Additional path for templates #6

Open
su-bzero opened this Issue · 7 comments

2 participants

@su-bzero

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
Owner

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?

@su-bzero

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.

@su-bzero su-bzero closed this
@su-bzero su-bzero reopened this
@su-bzero

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

@su-bzero

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
Owner

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.

@su-bzero

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

@lestrrat
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.