Styling Widgets with Widget Templates¶
Widget templates are used to customize the appearance and functionality of various existing widgets. Creating a widget template allows you to use a script to adapt the widget appearance and functionality. You can create a widget template for many widgets available out-of-the-box with Liferay, such as the Asset Publisher and Media Gallery widgets.
Creating a Widget Template¶
Follow these steps to create a widget template
From the Product Menu, click Site Builder → Widget Templates.
Click the Add (
) button, then select which widget to create a widget template for (e.g., Asset Publisher).
Add a name for your widget template.
Under the Script section, click into the body of the template editor.
Click one of the fields in the Fields menu to insert that field into the editor. The value of the field will be displayed when your widget template is used.
Note
Clicking any of the fields in the menu will insert the field name wherever the cursor is. You can also begin typing a field name yourself (starting with “${“) to show suggestions for auto-completion.
Click Save to complete the template.
Applying a Widget Template¶
Once you have a widget template ready for a widget on one of your pages, follow these steps:
Click the Actions (
) icon on the appropriate widget, then click Configuration.
Find the Display Template drop-down menu, and select the name of the desired template.
Note
This drop-down menu is on the default tab, Setup, for most widgets. For the Asset Publisher widget, this setting is found under the Display Settings tab.
Click Save.
The widget has been modified to use a custom appearance. By using more advanced widget template scripts, you can further enhance the capabilities of your widgets.