Dear Andrew,

Thanks. Following is keyword for me.

The layout is just a part of the template functionality which you can use to return web pages.

Dear David,

Your solution below worked, thanks.

get '/' => sub {
    # get the template engine
    my $template_engine = engine 'template';

    # apply the layout (not the renderer), and return the result
    return $template_engine->apply_layout("Home Page");
};

I think the other solution is calling a template as follow

get '/' => sub {
   template 'dummy.tt', {
       'msg' => 'Home Page',
   };

dummy.tt
<% msg %>





On Thu, May 21, 2015 at 3:27 PM, David Precious <davidp@preshweb.co.uk> wrote:
On Thu, 21 May 2015 12:08:32 +0100
Andrew Beverley <andy@andybev.com> wrote:
> On Thu, 2015-05-21 at 13:04 +0300, Kadir Beyazlı wrote:
> > main.tt is loaded if I use a template at my code.
> > What is the reason main.tt is not loaded if I don't use a template?
>
> The idea is that you can have full control as to what you return to
> the browser. For example, you might want to return only some simple
> plain text, or maybe send a file to the browser, in which case
> wrapping in the main layout would break things.

^ This is indeed the right answer - applying the layout is part of the
template processing - so if you've used template() to generate content
from a template, the layout is applied, but if you've just returned
content, it's assumed that that's the content you want sent to the
client - in other words, whatever the route handler returns is what
goes to the client, whether that's the result of a template() call, or
just some content you generated.

If you want to apply the layout around some generated content without
having to put it in a template file, you can use the template engine's
apply_layout() method to do it, e.g.:

get '/' => sub {
    # get the template engine
    my $template_engine = engine 'template';

    # apply the layout (not the renderer), and return the result
    return $template_engine->apply_layout("Home Page");
};



--
David Precious ("bigpresh") <davidp@preshweb.co.uk>
http://www.preshweb.co.uk/     www.preshweb.co.uk/twitter
www.preshweb.co.uk/linkedin    www.preshweb.co.uk/facebook
www.preshweb.co.uk/cpan        www.preshweb.co.uk/github


_______________________________________________
dancer-users mailing list
dancer-users@dancer.pm
http://lists.preshweb.co.uk/mailman/listinfo/dancer-users



--
Kadir Beyazlı
Computer Engineer
GSM : +90 535 821 50 00