-
-
Save anonymous/a1c4d4a698f5f3648483 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=head2 Template inheritance | |
Inheritance takes the layout concept above one step further, the helpers | |
L<Mojolicious::Plugin::DefaultHelpers/"content"> and | |
L<Mojolicious::Plugin::DefaultHelpers/"extends"> allow you to build skeleton | |
templates with named blocks that child templates can override. | |
use Mojolicious::Lite; | |
# first > mylayout | |
get '/first' => {template => 'first', layout => 'mylayout'}; | |
# third > second > first > mylayout | |
get '/third' => {template => 'third', layout => 'mylayout'}; | |
app->start; | |
__DATA__ | |
@@ layouts/mylayout.html.ep | |
<!DOCTYPE html> | |
<html> | |
<head><title>Hello</title></head> | |
<body><%= content %></body> | |
</html> | |
@@ first.html.ep | |
%= content header => begin | |
Default header | |
% end | |
<div>Hello World!</div> | |
%= content footer => begin | |
Default footer | |
% end | |
@@ second.html.ep | |
% extends 'first'; | |
% content header => begin | |
New header | |
% end | |
@@ third.html.ep | |
% extends 'second'; | |
% content footer => begin | |
New footer | |
% end | |
This chain could go on and on to allow a very high level of template reuse. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment