[dancer-users] session variables inside the template?

Andrew Beverley andy at andybev.com
Wed Jan 28 09:05:02 GMT 2015


On Wed, 2015-01-28 at 10:49 +0200, Nikos Vaggalis wrote:
> Can you access session variables inside the TT template?
> Like if I set
>                 session 'display' =>10;
> in my controller, then how can I access the vaule from within the
> template? 

Just pass the value into the template, like you would any other
variable:

    template 'data' => {
        display => session('display')
    }

> And, how do I dereference a scalar reference passed to the template
> as : 
>
> my $myvalue=10
> 
> return template  '/data' => {    
>          total=>\$myvalue
>     };  

Is there a reason you are passing as a reference? If you're only
displaying it (which is all you should really be doing), then just pass
by value:

    my $myvalue=10;
    return template '/data' => {    
        total => $myvalue
    };  

And in your template:

The value is [% total %]




More information about the dancer-users mailing list