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,
-
Navigate to your site’s (the default DXP site in this example) Site Administration.
-
Open the Site Menu (), expand *Content and Data, and go to Web Content.
-
Select the Templates tab.
-
Click New. Enter a name for the template (for example, Template 1).
-
Click Select from the Properties section to choose the structure (for example, Structure 1).
-
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. -
Click Save when finished.
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.
Related Topics
- Web Content Templates
- [Page Fragments and Widgets]../../../site-building/creating-pages/page-fragments-and-widgets.md