如何包含部分内容?
How do I include partials?
我知道了:
main.vm
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> test </title>
</head>
<body>
$content
</body>
</html>
这应该作为将要包含的所有其他视图的默认模板。
例如这个:
example.vm
#define($content)
<div>
<p> Hello World ! </p>
</div>
#end
如何将该部分作为内容包含到 main.vm 文件中?
我是否正确定义了模板?
我无法从官方文档中弄清楚。
我正在使用 Spring 启动,一切设置正确。
所有模板都在同一个文件夹中:
/resources/templates
编辑:
主要想法是拥有一个样板 html 文件,其中包含所有脚本标签和 link 标签、头部和主体。
这应该是带有 $content 变量的主模板,这是每个其他页面的占位符。
现在每隔一个页面都应包含在该主页中。
我该如何实现?
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> test </title>
</head>
<body>
$content
##the templates you want to 'execute' and render
#parse("example.vm")
#parse("example1.vm")
##...
#parse("example-n.vm")
##The templates you want to 'render' but not 'execute' as velocity templates.
#include("include.vm")
#include("include1.vm")
#include("include2.vm")
##...
#include("include-n.vm")
</body>
</html>
这会有所帮助...
请注意:-
- 使用
#parse()
宏会 执行 模板,然后包含它。
- 使用
#include()
宏会将模板包含为 纯文本。
我知道了:
main.vm
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> test </title>
</head>
<body>
$content
</body>
</html>
这应该作为将要包含的所有其他视图的默认模板。
例如这个:
example.vm
#define($content)
<div>
<p> Hello World ! </p>
</div>
#end
如何将该部分作为内容包含到 main.vm 文件中? 我是否正确定义了模板?
我无法从官方文档中弄清楚。
我正在使用 Spring 启动,一切设置正确。
所有模板都在同一个文件夹中:
/resources/templates
编辑:
主要想法是拥有一个样板 html 文件,其中包含所有脚本标签和 link 标签、头部和主体。
这应该是带有 $content 变量的主模板,这是每个其他页面的占位符。
现在每隔一个页面都应包含在该主页中。
我该如何实现?
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> test </title>
</head>
<body>
$content
##the templates you want to 'execute' and render
#parse("example.vm")
#parse("example1.vm")
##...
#parse("example-n.vm")
##The templates you want to 'render' but not 'execute' as velocity templates.
#include("include.vm")
#include("include1.vm")
#include("include2.vm")
##...
#include("include-n.vm")
</body>
</html>
这会有所帮助...
请注意:-
- 使用
#parse()
宏会 执行 模板,然后包含它。 - 使用
#include()
宏会将模板包含为 纯文本。