Hi Gabor,

I hope things are good with you.

I was doing something somewhat similar. I ended up creating a custom view class since i had the same  issues with adding to the TT INCLUDE_PATH.

Here is quick blog post with code on what i did: http://blog.leecarmichael.com/2013/03/altering-tts-includepath-in-dancer-with.html

Sorry its not too verbose but please ask any questions and I'll do my best to remember WTF i was doing back then :)

Take Care,

Lee


On Thu, Mar 28, 2013 at 4:38 AM, Gabor Szabo <gabor@szabgab.com> wrote:
Hi,

The http://perl5maven.com/ site is using Dancer and Template::Toolkit.
Since the opening of the Brazilian Portuguese translation at
http://br.perl5maven.com/
They both run from the same instance of the application.

I made some change to accommodate for the multiple language - the source of
the pages are in separate directories now, and in the config.yml I
have a section
with some configuration parameters for each site.
The application itself looks at request->host and pick the correct
part of the configuration.

So far it was good, but there were a few things that were left in
English in the Portuguese site,
and some things where I had both the English and the Portuguese text
in the central template.
As I am expecting a few more translations to appear[1] I wanted to
split some of the templates too.

The problem I found is that I cannot set the  INCLUDE_PATH dynamically
as I don't seem
to have access to the Template::Toolkit object. If I am not mistaken
it is located in the
$_engine variable in the Dancer::Template::TemplateToolkit module and
it is not accessible
from the outside world.

So what I did was adding the following to the before hook:

# Create a new Template::Toolkit object for every call because we
cannot access the existing object
# and thus we cannot change the include path before rendering
my $engines = config->{engines};
$engines->{template_toolkit}{INCLUDE_PATH} = ["$appdir/views",
mymaven->{articles} . '/templates'];
Dancer::Template::TemplateToolkit->new( name => 'template_toolkit',
type => 'template' , config => $engines->{template_toolkit});


This is hacky. Do you have a better suggestion to solve this issue?


regards
   Gabor

[1] If you know someone who'd be interested in helping in
translations, please let me know.
_______________________________________________
dancer-users mailing list
dancer-users@dancer.pm
http://lists.preshweb.co.uk/mailman/listinfo/dancer-users