gpt4 book ai didi

perl - 如何为 mojolicious lite 应用程序使用通用模板?

转载 作者:行者123 更新时间:2023-12-04 05:26:11 27 4
gpt4 key购买 nike

 use Mojolicious::Lite;

# /with_layout
get '/a' => sub { my $self = shift;} ;
get '/b' => sub { my $self = shift;} ;
get '/c' => sub { my $self = shift;};

app->start;
__DATA__

@@ a.html.ep
<!DOCTYPE html>
<html>
<head><title><%= title %></title></head>
<body><%= content %></body>
<table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>
</html>

@@ b.html.ep
<!DOCTYPE html>
<html>
<head><title><%= title %></title></head>
<body><%= content %></body>
<table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>
</html>


@@ c.html.ep
<!DOCTYPE html>
<html>
<head><title><%= title %></title></head>
<body><%= content %></body>
<table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>
</html>

我真的很感动
 <table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>

并使用所有 html 而不是添加到每个 html

最佳答案

使用 layout模板功能。

use Mojolicious::Lite;

# /with_layout
get '/a' => sub { my $self = shift;};
get '/b' => sub { my $self = shift;};
get '/c' => sub { my $self = shift;};

app->start;
__DATA__

@@ a.html.ep
% title 'A';
% layout 'template';
Content for 'A'

@@ b.html.ep
% title 'B';
% layout 'template';
Content for 'B'

@@ c.html.ep
% title 'C';
% layout 'template';
Content for 'C'

@@ layouts/template.html.ep
<!DOCTYPE html>
<html>
<head><title><%= title %></title></head>
<body><%= content %></body>
<table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>
</html>

关于perl - 如何为 mojolicious lite 应用程序使用通用模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13182202/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com