[Dancer-users] Keeping values on a form
David Precious
davidp at preshweb.co.uk
Fri Dec 17 12:22:15 CET 2010
On Thursday 16 December 2010 23:53:29 Naveed Massjouni wrote:
> On Thu, Dec 16, 2010 at 6:43 PM, David Precious <davidp at preshweb.co.uk>
wrote:
> > "Naveed Massjouni" <naveedm9 at gmail.com> wrote:
> >>By passing params() into your template vars hash, it is evaluated in
> >>list context, so they will get expanded into key/value pairs and they
> >>will all get propogated to your template.
> >>
> > I believe they're already passed in under params, so you can use e.g.:
> >
> > [% params.foo %]
> >
> > Not 100% certain, though.
> Whoa, you are right, in the template you can access params. So now I
> know of 3 things Dancer provides you in the templates: request,
> session and params. Are there any others? Lets document this
> somewhere. Maybe in the Dancer::Template pod?
Yeah, it should certainly be documented more clearly!
The cookbook does mention it:
"In order to render a view, just call the template keyword at the end of the
action by giving the view name and the HASHREF of tokens to interpolate in the
view (note that for convenience, the request, session and route params are
automatically accessible in the view, named request, session and params) - for
example:"
It would be nice to briefly mention it in the docs for the template() keyword
in Dancer.pm, and perhaps in Dancer::Template too.
The actual setting of those default tokens occurs in Dancer::Helpers::template
- the code is:
# these are the default tokens provided for template processing
$tokens ||= {};
$tokens->{dancer_version} = $Dancer::VERSION;
$tokens->{settings} = Dancer::Config->settings;
$tokens->{request} = Dancer::SharedData->request;
$tokens->{params} = Dancer::SharedData->request->params;
if (setting('session')) {
$tokens->{session} = Dancer::Session->get;
}
So, you can do things in your template like:
Hello there, [% session.username %] and welcome to [% settings.appname %]
You asked for [% request.path %]
Powered by Dancer [% dancer_version %]
On an entirely unrelated note, the fact my signature remained in the quoted
message in your reply showed me that my signature separator on my phone is
apparently messed up (missing the trailing space) - d'oh!
Cheers
Dave P
More information about the Dancer-users
mailing list