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 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.
The usage of macros is incorrect, please refer to the following