Mojolicious::Liteでテンプレートに値を渡す

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env perl
use Mojolicious::Lite;

get '/' => sub {
    my $c    = shift;
    my $user = $c->param('user');
    $c->stash(hello => qq{Hello $user!});
    $c->render(template => 'index');
};

app->start;
__DATA__
@@ index.html.ep
<!DOCTYPE html>
<html>

<head>
    <title>title</title>
</head>

<body>
    <form action="/">
        <input name="user" type="text">
        <input type="submit" value="Submit!">
    </form>
    <p><%= $hello %></p>
</body>

</html>
1
2
3
4
5
6
get '/' => sub {
    my $c    = shift;
    my $user = $c->param('user');
    $c->stash(hello => qq{Hello $user!});
    $c->render(template => 'index');
};
1
<%= $hello %>
1
2
3
action, app, cb, controller, data, extends,
format, handler, json, layout, namespace,
path, status, template, text, variant

Comments

comments powered by Disqus