Styling and Formatting Web Content
Loading Audio...
One of the core expectations for any digital experience solution is to render web content on site pages. Module 3 introduced structured web content as one of the fundamental page components in Liferay. In this lesson, you'll learn how to dynamically inject structured web content into your site with templates. Dynamic content injection is a process by which you can modify web content based on its location or context within a site. With a well-defined templating strategy for injecting web content, you can create engaging user experiences that feel personalized without sacrificing consistency in visual identity.
Understanding Web Content
To support dynamic content injection, Liferay separates web content into two parts: structure and template. The web content structure is a set of fields that define the required information for an article: title, author, body, date, etc. The web content template uses a combination of HTML and FreeMarker to define how the article appears in site pages.
Unlike many other content management solutions, Liferay provides the ability to create more than one template for a single structure. This means you can dynamically inject content into your site by implementing different web content templates for different pages. By separating structure and template this way, both designers and content managers can create and maintain their web content assets independently.
Maintenance becomes even more efficient with this web content approach. Updates to either a structure or a template are propagated automatically to any place it is used in a site. This reduces overhead and minimizes human error, so that your work effort does not have to scale with your solution.
Web content templates do require some developer expertise to implement. However, once you have a set of predefined templates, you can empower non-technical users in your organization to take content creation and page design into their own hands.
Best Practices for Web Content Templates
While web content templates provide robust options for customizing content presentation, modern solution implementations are usually better served by the content-mapping capability of Liferay fragments. This topic was covered in Module 3. However, there are specific scenarios in which using a web content template is a valid approach.
If your organizational policy demands strict, immutable formatting for a solution such as a corporate blog, you can use a web content template to enforce consistency. In this case, the uniform styling of all the content lends itself well to the use of a predefined template. You can achieve the same result with a fragment, but this particular use case does not require the flexibility that fragments provide.
Web content templates are also appropriate for content that is frequently updated. For example, you might implement a template for displaying product specifications on hundreds of different product pages. You can update the styling and formatting on all product pages automatically by modifying the web content template just once. Again, you can achieve the same result with fragments, though they require additional configuration to propagate changes automatically. Web content templates propagate changes by default.
There are additional scenarios where web content templates are the only option due to limitations in the fragment mapping approach. With fragments, you can only map content fields one-to-one with corresponding sub-element fields. If your content requires business logic to control rendering at the field level, you should implement that logic with FreeMarker in a web content template.
Furthermore, some web content structures make use of the repeatable fields feature. Repeatable fields are commonly used to represent lists, such as instructional material that provides a series of steps. Mapping repeatable fields to fragments is a relatively new feature that is currently behind a release feature flag. Instead, you can use a web content template to render a structure that uses repeatable fields.
Conclusion
Liferay web content separates the structure from the template to streamline content creation and page design for designers, creators, and developers. Although fragment mapping is the recommended best practice approach for designing modern web solutions, there are specific cases where web content templates are viable and even necessary. Clarity eventually plans to produce web content with repeatable fields, such as a troubleshooting guide, and their design team recognizes the utility of web content templates to overcome some of the current limitations of fragment mapping.
Next, you'll learn more about standardizing layouts to display any type of content.
Capabilities
Product
Education
Contact Us