Embedding Widgets in Templates

You can embed widgets in web content templates: it doesn’t matter whether they’re core apps, custom apps, instanceable, or non-instanceable. Below is an example of embedding a Web Content widget in FreeMarker:

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

To begin embedding widgets in your web content templates, follow these steps:

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

  2. Click Content & DataWeb Content.

  3. Click on the Templates tab.

    The Templates tab shows the templates in your Site.

  4. Click the Add (Add Icon) icon.

  5. Enter a name for the template (for example, Template 1)

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

    Select a structure.

  7. 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.

  8. Click Save when finished.


The theme variable is no longer injected into the FreeMarker context. For more information about why the theme variable was removed for DXP 7.0 and suggestions for updating your code, visit the Taglibs Are No Longer Accessible via the theme Variable in FreeMarker breaking change entry.

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 view the Edit page for a template.

Additional Information