Changing date format in fragment mapping

Issue

  • I would like to change the display date format of content mapped on a fragment without having the hours and minutes. The current date format is DD/MM/YYYY HHmm.

Reproduction Steps:

1. Set up DXP 7.4
2. Go to Content & Data --> Web Content and add basic web content.
3. Go to Design --> Page Templates --> Display Page Templates and add a DPT with "Web Content Article" as the "Content Type" and "Basic Web Content" as the Subtype.
4. On the DPT add a paragraph fragment, click on the fragment --> Element Text, and at the "Mapping" select the web content at the "Source" and set the "Field" to Display Date at the "Schedule".
5. Check the fragment.

Actual Result: The date format is DD/MM/YYYY HHmm (the DD and MM positions depend on if it is the US or Europe).

Expected Result: Something like the Day of the display date, DD/MM/YYYY (for example, Thursday, 21/07/22)

Environment

  • Liferay DXP 7.4

Resolution

  • There is an alternative method to achieve this. It is always possible to map a fragment to a Template defined for the given structure. The idea of this feature is to be able to add logic before the real mapping (logic will be added with the template with freemarker). It's the same idea you would follow if you have repeatable fields in the structure and want to display them in a DPT. You can find below the required information: Mapping Web Content Templates to Fragments

  • Another approach would be customization. The behavior is determined by DateInfoTextFormatter class. If you would like to change this format, you could blacklist that class and deploy a custom module that contains a new implementation for the interface InfoTextFormatter<Date> according to your requirements. This change would apply to all the mapped date fields. This formatting option could be available from the UI where the field mapping is set up. For this purpose, you can submit a feature request
这篇文章有帮助吗?
0 人中有 0 人觉得有帮助