Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

current route of perl dancer

by lightoverhead (Pilgrim)
on Feb 09, 2014 at 19:46 UTC ( #1074158=perlquestion: print w/replies, xml ) Need Help??

lightoverhead has asked for the wisdom of the Perl Monks concerning the following question:


Does anyone know if there is a name to refer to the current route?

for example, I have "http://localhost/abc". I would like to have some variable, such as "current_route" to refer the route of "/abc" or just "abc". Then I can use it a template tt file as <% current_route %>.

I can find some other way to go round this. but a direct name would be nice.


Replies are listed 'Best First'.
Re: current route of perl dancer
by webfiend (Vicar) on Feb 09, 2014 at 21:23 UTC

    You might be looking for the Dancer::Request method path. You get at a Dancer::Request object via request.

    # in hook before_template_render => sub { my $tokens = shift; # Make the path available in every template. $tokens->{current_route} = request->path; }; # in views/layouts/ <p>Route: <% current_route %></p>

    Anything more elaborate than what I did, you'll probably want to create a custom helper.

      Thank you guys. Nice solution!
Re: current route of perl dancer
by Anonymous Monk on Feb 10, 2014 at 00:15 UTC
    See also  request()->{'_route_pattern'} but heed the warning from source of Dancer::Route
Re: current route of perl dancer
by Anonymous Monk on Feb 10, 2014 at 20:58 UTC
    Also note that "template variables" can be very powerful things indeed, if you equate them to anonymous subroutines e.g. ... => sub { do something here ... }. (A subroutine reference may be required.) This usage will execute code every time the variable is referenced in the template, not just prior to displaying the template.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1074158]
Front-paged by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2022-01-20 17:42 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (57 votes). Check out past polls.