Liferay DDLs are quite useful for dealing with small sets of custom data, for which it would be overkill to create a new service. Our event microsites use DDLs extensively for displaying speaker, agenda and sponsor information. Through the the Skinny JSON Provider, our DDL data information is even served via JSON-WS for use in the Liferay Events App. How cool!
DDL templates perform the magic of transforming custom DDL data to HTML and are easy to write in Freemarker or Velocity.
But what if you need to reuse DDL templates in various contexts? DDL templates do not, as far as I am aware, offer any options for configuration. For example, we have a common agenda DDL definition for Liferay events. Since the events themselves take place in different countries there are many aspects of the displayed agenda that are country or region specific (date formatting, header text, etc.). With standard DDL templates, there is no simple way to reuse a DDL template in different contexts.
One idea to solve this problem is to use custom web content structures. A web content structure is created with a field for the DDL record set id and whichever other fields need to be configured. Then a web content article is created where the particular record set id is set and the standard Web Content Display portlet is used to display the template.
In the code there is hardly any difference. Instead of using the automatically set record set id value ( $reserved_record_set_id.data), we instead use our own field definition, e.g. "record_set_id" to retrieve and process and DDL records in the template:
## Get DDL Records
#set ($ddl_records_local_service = $serviceLocator.findService("com.liferay.portlet.dynamicdatalists.service.DDLRecordLocalService"))
#set ($record_set_id = $getterUtil.getLong($record_set_id.data))
#set ($records = $ddl_records_local_service.getRecords($record_set_id))
Then we are free to define whatever other fields we need for further customizing the DDL display. This has the following advantages compared to using standard DDL templates:
Here is an example of using this approach to configure the display of sponsors. The header text can be configured in the "sponsor_header_text" field. The text for displaying "Platinum" sponsors can be configured in the "sponsor_text" field.
One thing to keep in mind is that you might run into problems with cached DDL data, as by default web content templates are cached.
DDL Templates and Web Content structures - two great tastes that taste great together!