Freemarker include in Liferay

Quick Tip:

In Liferay Web Content Templates using Freemarker, you can include another template using the <#include > directive. The trick is that you have to prepend the templatesPath variable (available in the left sidebar) and then call the templates by it's template key, which can be found in the Details section when you edit the included template. So to include a template with the key 12345 you would write:

<#include "${templatesPath}/12345" />

Easy, huh? This also works with the <#import > directive.

<#import "${templatesPath}/12345" as libraryname />

<@libraryname.librarymacro a="something" b="something else" />

Which opens up the possibilities of creating libraries of macros and functions that make it easier to use Liferay's API in your web content templates.

One note is that while this works for Web Content, as of Liferay 6.2 CE this does not work for ADTs, which is a shame. Still, anything that removes some of the pain of working with Liferay is a good thing.

Nothing Interesting here.