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?
阿神2017-05-27 17:43:00
Freemarker is not based on layout. It only does expression evaluation and text replacement, which cannot meet your requirements.
As far as I know:
Struts and Tiles plug-in can achieve the layout effect you want.
Thymeleaf combined with thymeleaf-layout-dialect can also achieve the effect you want.
我想大声告诉你2017-05-27 17:43:00
The usage of macros is incorrect, please refer to the following
<!-- 定义宏用 <#macro macroName parameterList> -->
<#macro list title items>
<p>${title?cap_first}:
<ul>
<#list items as item>
<li>${item}
</#list>
</ul>
</#macro>
<!-- 调用宏用 <@macroName arguments> -->
<@list items=animals title="animals"/>