Behaviour doesn't comply to the doc. #785

Closed
arhuman opened this Issue Apr 26, 2012 · 7 comments

Comments

Projects
None yet
4 participants

arhuman commented Apr 26, 2012

According to https://metacpan.org/module/Dancer::Cookbook#Using-templates---views-and-layouts
I've try to access session variable from my template (a layout to be precise).

The used routes :
post '/login' => sub {
my $auth = Dancer::Plugin::Auth::RBAC::auth( params->{user}, params->{password} );
if ( !$auth->errors ) {
var user => session('user');
session username => 'TOTO';
redirect params->{path};
}
else {
print $auth->errors;
}
};

get '/logout' => sub {
session->destroy;
redirect '/';
};

In my template :
AA
<% vars.user.name %>
<% session %>
<% session.user %>
<% session.username %>
<% settings.environment %>
BB

What is rendered

            AA

            Dancer::Session::Simple=HASH(0x9119f84)


            development
            BB

I'm using Dancer 1.3011

In my config.yml

appname: "JN::TemplateStore"
layout: "main"
charset: "UTF-8"
template: "simple"
session: "simple"
plugins:
Database:
driver: "SQLite"
database: "WebTemplate.sqlite"
Auth::RBAC:
credentials:
class: SQLite
permissions:
class: Config

arhuman commented Apr 26, 2012

Dancer is version 1.3095 of course
(1.3011was a mistake...)

arhuman commented Apr 26, 2012

In my case the issue was workarounded (thanks to MST) using :

hook 'before_template' => sub {
my $user = session 'user';
var user => $user->{name};
};

and <% vars.user %> in the template

arhuman commented Apr 27, 2012

FYI: Switching from Dancer::Template::Simple to Template::Toolkit
(template: "template_toolkit" #in my config.yml)
allows the use of <% session.user.name %> without a glitch.

pughpugh commented Jan 8, 2013

I've also just witnessed the same issue.

Dancer 1.3110.

Owner

bigpresh commented Jan 8, 2013

The issue was, it seems, using a template engine that doesn't understand dot notation; TT understands e.g. <% session.user %>, whereas Dancer::Template::Simple is far more basic and doesn't do that.

That should probably be documented more clearly.

pughpugh commented Jan 8, 2013

Ah ok, that makes sense. Thanks.

Contributor

yanick commented Aug 3, 2013

As bigpresh said, it's the template system that doesn't map session.user to the perl call session( 'user' ). Closing the issue.

yanick closed this Aug 3, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment