Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional path for templates #6

Open
ghost opened this issue May 19, 2011 · 7 comments
Open

Additional path for templates #6

ghost opened this issue May 19, 2011 · 7 comments

Comments

@ghost
Copy link

ghost commented May 19, 2011

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
Copy link
Collaborator

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
Copy link
Author

ghost commented May 19, 2011

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 ghost closed this as completed May 19, 2011
@ghost ghost reopened this May 19, 2011
@ghost
Copy link
Author

ghost commented May 19, 2011

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

@ghost
Copy link
Author

ghost commented May 19, 2011

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
Copy link
Collaborator

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
Copy link
Author

ghost commented May 22, 2011

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

@lestrrat
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant