Posts

Showing posts with the label adt

ADT Template - fetch DDMTemplate by name

Problem : sometimes you may need to access DDMTemplate in the asset publisher template, you know it’s name and you need to fetch it by name, but, unfortunately, there is no such service for that - you can fetch it only by templateKey: public DDMTemplate getTemplate( long groupId, long classNameId, String templateKey)  As templateKey is generated automatically - it’s not a good idea to hard-code it directly in ADT. Solution : here is an FTL function, which finds the required DDMTemplate in Global scope using the template name: <#function getDDMTemplateByName templateName >    <#assign ddmTemplateLocalService = serviceLocator . findService ( "com.liferay.dynamic.data.mapping.service.DDMTemplateLocalService" ) />    <#assign companyLocalService = serviceLocator . findService ( "com.liferay.portal.kernel.service.CompanyLocalService" ) />    <#assign portalUtil = staticUtil [ "com.liferay.portal.ker...

Fixing missing variables in ADT Template

Image
Fixing missing variables in ADT Template You may get error for missing variable in your custom ADT template, like this: The following has evaluated to null or missing: ==> staticUtil  [in template… To fix this - you need to remove it from restricted variables. 1. Go to Control Panel -> Configuration -> System setting -> Foundation. 2. Search for ‘Freemarker’. 3. Click ‘Edit’ for ‘Freemarker Engine’. 4. Remove ‘staticUtil’ from restricted variables and save configuration: (you may also remove other variables you need) Note: this settings may not be applied on-the-fly, Liferay restart may be needed. After this you may use Liferay restricted variables in your ADT templates 😏