Nesting layouts fails
rnkn opened this issue · comments
Paul W. Rankin commented
- Mojolicious version: 9.35, Waffle
- Perl version: v5.38.2
- Operating system: macOS 14.2.1 (23C71)
A few sources have told me that Mojolicious supports nested layouts, but these don't appear to work. The log indeed reports loading both templates, however the result only renders the topmost template.
If I'm doing something wrong here any pointers would be helpful.
Steps to reproduce the behavior
$ mojo generate lite-app nesting.pl
...
$ cat nesting.pl
#!/usr/bin/env perl
use Mojolicious::Lite -signatures;
get '/' => sub ($c) {
$c->render(template => 'index');
};
app->start;
__DATA__
@@ index.html.ep
% layout 'main';
% title 'Welcome';
<h1>Welcome to the Mojolicious real-time web framework!</h1>
@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
<head><title><%= title %></title></head>
<body><%= content %></body>
</html>
@@ layouts/main.html.ep
% layout 'default';
<main>
<%= content %>
</main>
<footer>
This content is the footer.
</footer>
$ morbo nesting.pl
Expected behavior
$ curl 127.0.0.1:3000
<!DOCTYPE html>
<html>
<head><title>Welcome</title></head>
<main>
<body><h1>Welcome to the Mojolicious real-time web framework!</h1>
</main>
<footer>
This is the footer content.
</footer>
</body>
</html>
Actual behavior
$ curl 127.0.0.1:3000
<!DOCTYPE html>
<html>
<head><title>Welcome</title></head>
<body><h1>Welcome to the Mojolicious real-time web framework!</h1>
</body>
</html>