Reputation: 13
I`m trying to build an app with spring boot and freemarker as template engine. The problem I have is, I want to make a "master template" for all my pages to use. I found out that this is achievable in Freemarker with macros. This is how my indexmaster.ftl looks like:
[#macro indexmaster title="defaultTitle"]
<html>
<head> css stuff </head>
<body>
<div id="content">[#nested /]</div>
</body>
</html>
[/#macro]
and in the other pages, I use the macro like this:
[#import "/WEB-INF/ftl/master/indexmaster.ftl" as layout /]
[@layout.indexmaster title="My title"]
...rest of the page
[/@layout.indexmaster]
The problem I`m facing is, the freemarker "code" is interpreted as text when I access the page
What am I doing wrong? Is there any extra spring boot configuration needed?
Upvotes: 1
Views: 1166
Reputation: 31112
You need to set the tag_syntax
configuration setting of FreeMarker to auto_detect
or square_bracket
. The default is angle_bracket
for backward compatibility. Another option is to start the template with [#ftl]
, which turns on square bracket syntax even if tag_syntax
is angle_bracket
.
Upvotes: 1