Re: [Dancer-users] Private template in Dancer
[ add dancer-users@perldancer.org in CC ] Le 15/06/2010 09:14, igor.bujna@post.cz a écrit :
Hello,
Hello, First of all, please post this kind of question directly to the users mailing list, that way more people give attention to your problem and the better the support you get.
sory for my bad english first. I try yours super framework and for me is missing than global vars for template. I wanna defined something in before{} func and this will be in every template. Forr me is simplest show how i use. I call this as 'private_template' and its must be vars like that:
set private_template => '1'; before sub { var private_template => { test => "Hello world", }; };
I must make this patch for Dancer/Helper.pm --- Dancer/Helpers.pm~ 2010-06-09 22:37:44.000000000 +0200 +++ Dancer/Helpers.pm 2010-06-10 21:53:29.000000000 +0200 @@ -54,6 +54,12 @@ $tokens->{session} = Dancer::Session->get; }
+ my $pt = exists($options->{'private_template'}) + ? $options->{'private_template'} : setting('private_template'); + if ($pt) { + $tokens->{private} = Dancer::SharedData->vars->{'private_template'}; + } + my $content = Dancer::Template->engine->render($view, $tokens); return $content if not defined $layout;
------------------------------------------------------------------------------------------------------------------------------------------- Now in every template i can use this variables via 'private' call. It must be enabled for every template via set private_template => '1' Or can enabled or disabled separately in options 'private_template' in given using template.
It would be good to make something similar in this framework.
Thank you and make dance Igor Bujna
Well, Franck Cuny has been rewriting a lot our template engiens recently and I'd like to have his point of view on this. My first opinion is that using settings for private template variables is not a good idea. Setting should remain.... setting ;) We also had in mind to provide a new kind of hook, called "before_template" which could process variables before any template is called. So I suppose we should wait for feedback from the team first. Regards, -- Alexis Sukrieh
On Tuesday 15 June 2010 09:18:11 Alexis Sukrieh wrote:
Le 15/06/2010 09:14, igor.bujna@post.cz a écrit :
Now in every template i can use this variables via 'private' call. It must be enabled for every template via set private_template => '1' Or can enabled or disabled separately in options 'private_template' in given using template.
It would be good to make something similar in this framework.
My first opinion is that using settings for private template variables is not a good idea. Setting should remain.... setting ;)
Agreed :)
We also had in mind to provide a new kind of hook, called "before_template" which could process variables before any template is called.
I would definitely agree, this is a good case where using a before_template hook would be nice, it could inject whatever params it wanted into the hashref of params about to be passed off to the template. FWIW, one way that may be suitable to handle this is to shove something in the session, if you're using sessions, then the template can access that. For instance, session 'foo' => $foo; Then, in the template, [% session.foo %] Once we have proper hook support, implementing it with a before_template hook would probably be cleaner, though!
Hello, i make cleaner code for "private template". I use similar code as "before" filter. Better is when you looking my patch than I write how it works. Now its simply and cleaner :)
------------ Původní zpráva ------------ Od: David Precious <davidp@preshweb.co.uk> Předmět: Re: [Dancer-users] Private template in Dancer Datum: 15.6.2010 12:06:54 ---------------------------------------- On Tuesday 15 June 2010 09:18:11 Alexis Sukrieh wrote:
Le 15/06/2010 09:14, igor.bujna@post.cz a écrit :
Now in every template i can use this variables via 'private' call. It must be enabled for every template via set private_template => '1' Or can enabled or disabled separately in options 'private_template' in given using template.
It would be good to make something similar in this framework.
My first opinion is that using settings for private template variables is not a good idea. Setting should remain.... setting ;)
Agreed :)
We also had in mind to provide a new kind of hook, called "before_template" which could process variables before any template is called.
I would definitely agree, this is a good case where using a before_template hook would be nice, it could inject whatever params it wanted into the hashref of params about to be passed off to the template.
FWIW, one way that may be suitable to handle this is to shove something in the session, if you're using sessions, then the template can access that.
For instance,
session 'foo' => $foo;
Then, in the template,
[% session.foo %]
Once we have proper hook support, implementing it with a before_template hook would probably be cleaner, though!
_______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
Hello, in function 'sub run_before_template_filters' will be beter put this code $tokens->{$k} = $d if (!exists($tokens->{$k})); To controling if from function before_template can't change something putted in $tokens in given function. My idea with before_template is this. I want put some standart definition like own function which wil be called from every template or given template enabled or disabled via options 'before_template' in template definition. Like this: use URI::Escape (); set before_template => '1'; before_template sub { return { urlencode => sub { return URI::Escape::uri_escape(@_); }, urldecode => sub { return URI::Escape::uri_unescape(@_); }, }; }; Now in every called template i can use function for decode|encode codepage string like this: [% urlencode(" hello " %]
------------ Původní zpráva ------------ Od: <igor.bujna@post.cz> Předmět: Re: [Dancer-users] Private template in Dancer Datum: 30.6.2010 07:50:40 ---------------------------------------- Hello, i make cleaner code for "private template". I use similar code as "before" filter. Better is when you looking my patch than I write how it works. Now its simply and cleaner :)
------------ Původní zpráva ------------ Od: David Precious <davidp@preshweb.co.uk> Předmět: Re: [Dancer-users] Private template in Dancer Datum: 15.6.2010 12:06:54 ---------------------------------------- On Tuesday 15 June 2010 09:18:11 Alexis Sukrieh wrote:
Le 15/06/2010 09:14, igor.bujna@post.cz a écrit :
Now in every template i can use this variables via 'private' call. It must be enabled for every template via set private_template => '1' Or can enabled or disabled separately in options 'private_template' in given using template.
It would be good to make something similar in this framework.
My first opinion is that using settings for private template variables is not a good idea. Setting should remain.... setting ;)
Agreed :)
We also had in mind to provide a new kind of hook, called "before_template" which could process variables before any template is called.
I would definitely agree, this is a good case where using a before_template hook would be nice, it could inject whatever params it wanted into the hashref
of params about to be passed off to the template.
FWIW, one way that may be suitable to handle this is to shove something in the
session, if you're using sessions, then the template can access that.
For instance,
session 'foo' => $foo;
Then, in the template,
[% session.foo %]
Once we have proper hook support, implementing it with a before_template hook
would probably be cleaner, though!
_______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
participants (3)
-
Alexis Sukrieh -
David Precious -
igor.bujna@post.cz