<div dir="ltr">Hi Jean-Marie.<br><br><div class="gmail_extra">Welcome! :)<br><br></div><div class="gmail_extra">Let's go over the code you showed.<br><br>
> get '/index' => sub { template 'index' };<br><br></div><div class="gmail_extra">That will declare a path "/index" for a GET request which will render a template called (if you're using the default templating framework) "<a href="http://index.tt">index.tt</a>". So far so good.<br><br>
> get '/' => sub { template 'login' };<br><br></div><div class="gmail_extra">When someone goes to the main page, render '<a href="http://login.tt">login.tt</a>'.<br><br></div><div class="gmail_extra">
> get 'test' => sub {<br>
> template 'test';<br>
> };<br><br></div><div class="gmail_extra">You probably want to change this to "get '/test'" instead of "get 'test'". Paths should begin with "/", almost always.<br></div><div class="gmail_extra"><br>> #return '<script> document.location("./views/<a href="http://test.tt" target="_blank">test.tt</a>");</script>';<br><br></div><div class="gmail_extra">In this case, you want to simply use "redirect" keyword which would do this for you:<br>get '/test' => sub {<br> redirect "/"; # redirect to main page<br>};<br><br></div><div class="gmail_extra">In your example, you're trying to redirect to "./views/<a href="http://test.tt">test.tt</a>" which is a file. HTTP redirects are for *paths*, not *files*.<br><br>If you want people who go to "/wrong/place" to go to "/test" which renders the right template ("<a href="http://test.tt">test.tt</a>"), you would write this:<br></div><div class="gmail_extra">get '/wrong/place => sub { redirect '/test' };<br>get '/test => sub { template 'test'; }<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">Does this help?<br></div><div class="gmail_extra">S.<br></div><div class="gmail_extra"><br>On Mon, Sep 1, 2014 at 6:45 PM, <a href="mailto:jean-marie.bourbon@armaturetech.com">jean-marie.bourbon@armaturetech.com</a> <span dir="ltr"><<a href="mailto:jean-marie.bourbon@armaturetech.com" target="_blank">jean-marie.bourbon@armaturetech.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
<br>
On 09/01/2014 03:56 AM, <a href="mailto:jean-marie.bourbon@armaturetech.com">jean-marie.bourbon@armaturetech.com</a> wrote:<br>
> Hi guys!<br>
><br>
> I recently tried to build my own web application using Dancer but I'm a basic perl developer and I have any interrogations about this framework.<br>
><br>
> I've first tried to build a login page based on your "navbar_login" example.<br>
> Once logged in I try to call another page named "test" but it seems to not work (I don't know how to call my page and how Dancer work exactly .. to be honest :-( . )<br>
> :<br>
> I have a <a href="http://login.pm" target="_blank">login.pm</a> module, <a href="http://main.tt" target="_blank">main.tt</a> (in views/layout/) <a href="http://index.tt" target="_blank">index.tt</a> and <a href="http://test.tt" target="_blank">test.tt</a> in views.<br>
> Im my <a href="http://login.pm" target="_blank">login.pm</a> I have declared my routes as following:<br>
><br>
> get '/index' => sub { template 'index' };<br>
><br>
> get '/' => sub { template 'login' };<br>
><br>
> get 'test' => sub {<br>
> template 'test';<br>
> };<br>
><br>
> So, once logged in I try (and fail) to call my page like this:<br>
><br>
><br>
> elsif($password eq "12345") {<br>
> #print "ok";<br>
> #return '<script> document.location("./views/<a href="http://test.tt" target="_blank">test.tt</a>");</script>';<br>
> #return template 'examples/photo_carousel';# 'index';<br>
> #my @animals = qw/dogs cats camels mooses vogons/;<br>
> return template 'test' => {<br>
> show => "launching <a href="http://test.tt" target="_blank">test.tt</a>",<br>
> };<br>
> #session $username => params->{$username};<br>
> #redirect params ->{'index'};<br>
><br>
> #show_<br>
> }<br>
><br>
> Fail also with redirect parameter .. But why and how to call my test page ?<br>
> I don't understand why it doesn't work, can you explain me please ?<br>
><br>
> Thanks a lot !<br>
><br>
_______________________________________________<br>
dancer-users mailing list<br>
<a href="mailto:dancer-users@dancer.pm">dancer-users@dancer.pm</a><br>
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
</blockquote></div><br></div></div>