Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

current route of perl dancer

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

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

Monks

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.

Thanks

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 app.pl hook before_template_render => sub { my $tokens = shift; # Make the path available in every template. $tokens->{current_route} = request->path; }; # in views/layouts/main.tt <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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-03-29 05:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found