template
<!DOCTYPE html>
<html>
<head>
<#include "baseHeader.html" />
<#macro head ><#nested></#macro>
<#macro style ><#nested></#macro>
</head>
<body>
<#macro content >
<#nested>
</#macro>
</body>
<#macro script >
<#nested>
</#macro>
</html>
Page call
<#include "/layout/master.ftl" />
<@script>var a=1;</@script>
In the page generated as a result, the sentence var a=1;
ran behind </html>
, that is, at the end of the template, and did not appear in the corresponding part of the template. Location.
I have been doing it for several years.net
, and I feel that it is natural for this kind of template to produce the effect I have.
But on java
, it seems that it is not easy to achieve the effect I expected?
freemarker不是基于layout的,它只是做表达式求值和文本替换,是不能满足你的要求的。
据我所知:
Struts配合Tiles插件可以达到你要的layout效果。
Thymeleaf配合thymeleaf-layout-dialect也可以达到你要的效果。
宏的用法不对,可以参考下面