"I welcome your tutorial."
use strict;
use warnings;
use Mojolicious::Lite;
my %pages = (
'/' => {
title => 'Begin',
blurb => 'This is where you begin.',
choices => [
{ text => 'Choice 1', link => '/foo' },
{ text => 'Choice 2', link => '/bar' },
],
},
'foo' => {
title => 'Foo',
blurb => 'This is what happens when you Foo.',
choices => [
{ text => 'End', link => '/end' },
],
},
'bar' => {
title => 'Foo',
blurb => 'This is what happens when you Bar.',
choices => [
{ text => 'Restart', link => '/' },
{ text => 'End', link => '/end' },
],
},
'end' => {
title => 'End',
blurb => 'This is the end.',
choices => [],
},
);
get '/' => { template => 'index', %{ $pages{'/'} } };
get '/:key' => sub {
my $c = shift;
my $key = $c->param('key');
return $c->reply->not_found unless $pages{$key};
$c->render( template => 'index', %{ $pages{$key} } );
};
app->start;
__DATA__
@@ index.html.ep
<html>
<head>
<!-- links to bootstrap here -->
<title><%= $title %></title>
</head>
<body>
<div class="container">
<h1><%= $blurb %></h1>
% for my $choice (@$choices) {
<a href="<%= $choice->{link} %>" class="btn btn-primary" role="but
+ton"><%= $choice->{text} %></a>
% }
</div>
</body>
</html>
All that extra code you have is unnecessary. |