mojolicious / mojo

:sparkles: Mojolicious - Perl real-time web framework
https://mojolicious.org
Artistic License 2.0
2.66k stars 576 forks source link

Nesting layouts fails #2138

Closed rnkn closed 6 months ago

rnkn commented 6 months ago

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>