Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: RE: How to setup custom macros for use like FTL_Liferay.ftl?
Hello,
Liferay DXP defines several macros in FTL_Liferay.ftl
template that
you can be used in theme templates to include theme resources,
standard portlets, and more. Liferay DXP also exposes its taglibs as
FreeMarker macros.
As a Frontend Developer, I would like to create a Macro based component library that can be accessed similar to FTL_Liferay.ftl. Where do I start, in that, where is the Macro library FTL saved, is any JSP required, since the resource-importer is depracated where is the FTL stored to be accessed globaly, most importantly accessed in Fragments.
Thanks & Regards
I'd avoid all of this nonsense myself. All too often it leads to Freemarker Abuse and translates into poor rendering performance.
Sure it may simplify your development of templates, but the ongoing penalties you pay from it will far exceed the cost.
Instead, look to simple templates doing simple things and, when you have complex logic to apply, use a TemplateContextContributor to inject a java instance that takes care of all of the complexity.
It is actually quite simple to do that. Just add the ftl file to the resources folder in a module, e.g.
my-module
- bnd.bnd
- build.gradle
- src/main/resources/mytemplates/MyMacros.ftl
- <other stuff, java files, ...>
Now you can include your template in other ftl files like this:
<#include "my-module_SERVLET_CONTEXT_/mytemplates/MyMacros.ftl" />
"my-module" is determined from the Bundle-Name or Bundle-SymbolicName from bnd.bnd (I don't recall which one)
Hi Christoph,
Thanks for providing a quick outline, very appreciated.
Regards
Said
Powered by Liferay™