Embedding Widgets in Web Content Templates

You can embed core or custom widgets, instanceable or not, in web content templates. Below is an example of embedding a web content widget in FreeMarker:

<@liferay_portlet["runtime"] portletName="com_liferay_journal_content_web_portlet_JournalContentPortlet" />

To embed widgets in your web content templates,

  1. Navigate to your site’s (the default DXP site in this example) Site Administration.

  2. Open the Site Menu (Site Menu), expand *Content and Data, and go to Web Content.

  3. Select the Templates tab.

    The Templates tab shows the templates in your site.

  4. Click New. Enter a name for the template (for example, Template 1).

  5. Click Select from the Properties section to choose the structure (for example, Structure 1).

    Select a structure for the template.

  6. Paste your macro (for example, <@liferay_portlet["runtime"] portletName="com_liferay_journal_content_web_portlet_JournalContentPortlet" />) in the Template Editor. Depending on whether your portlet is instanceable, you may need to enter the portlet ID.

    Enter the portlet macro.

  7. Click Save when finished.

Important

The theme variable is no longer injected into the FreeMarker context.

Embedding Other Templates

In addition to embedding widgets in templates, you can embed a template within another template. This allows for reusable code, JavaScript library imports, scripts, or macros.

Below is an example of embedding a template in FreeMarker:

<#include "${templatesPath}/[template-key]" />

You can find the Template Key when editing a previously published template.

You can find the Template Key when viewing the Edit page for a template.

  • Web Content Templates
  • [Page Fragments and Widgets]../../../site-building/creating-pages/page-fragments-and-widgets.md

Capabilities

Product

Contact Us

Connect

Powered by Liferay
© 2024 Liferay Inc. All Rights Reserved • Privacy Policy