Skip to content

Instantly share code, notes, and snippets.

@olegwtf
Forked from sharifulin/gist:335531
Created December 11, 2012 15:51
Show Gist options
  • Save olegwtf/4259527 to your computer and use it in GitHub Desktop.
Save olegwtf/4259527 to your computer and use it in GitHub Desktop.
Nested layouts for the Mojolicious
#!/usr/bin/env perl
use Mojolicious::Lite;
get '/' => 'index';
get '/ok' => 'index_ok';
use Test::More;
plan tests => 6;
use Test::Mojo;
my $result = "<!doctype html><html>\n<head><title>Funky!</title></head>\n<body>\nYea baby!\n\n</body>\n</html>\n";
my $t = Test::Mojo->new;
$t->get_ok('/ok')->status_is(200)->content_is($result);
$t->get_ok('/' )->status_is(200)->content_is($result);
__DATA__
@@ index.html.ep
% layout 'funky';
Yea baby!
@@ layouts/funky.html.ep
% extends 'layouts/base';
% content html => begin
<head><title>Funky!</title></head>
<body>
<%== content %>
</body>
% end
@@ layouts/base.html.ep
<!doctype html><html>
%= content html => begin
<%== content %>
% end
</html>
@@ index_ok.html.ep
% layout 'funky_base';
Yea baby!
@@ layouts/funky_base.html.ep
<!doctype html><html>
<head><title>Funky!</title></head>
<body>
<%== content %>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment