Skip to content

layout with variable from the stash #1801

Answered by rage311
Haf-Linger asked this question in Q&A
Discussion options

You must be logged in to vote

This seems to work as expected:

#!/usr/bin/env perl

use 5.034;
use Mojolicious::Lite -strict, -signatures;

get '/' => sub ($c) { $c->stash(refreshrate => 10) } => 'index';

app->start;

__DATA__

@@ index.html.ep
% layout 'refreshLayout', title => 'A title';
% content_for refresh => begin
  <meta http-equiv="refresh" content="<%= $refreshrate %>"/>
% end
<div>....body content ...</div>

@@ layouts/refreshLayout.html.ep
<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/>
    <meta charset="UTF-8"/>
    <%= content 'refresh' %>
  </head>
  <body><%= content %></body>
</html>

Generates the HTML content:

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@Haf-Linger
Comment options

Answer selected by Haf-Linger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants