Understanding and Using Page Templates in Liferay

Introduction
A Page Template in Liferay provides a predefined page layout and structure that can be reused when creating new pages. It is useful for maintaining consistency while allowing minor customizations per page.
Why are they useful?
- Helps quickly create new pages with a consistent structure.
- Can be modified at the individual page level after creation.
- Reduces manual effort in setting up similar pages.
When to Use Page Templates
On many websites, some pages share a similar layout, with only the content differing. In such cases, you can create a Page Template to maintain consistency and save time.
Instead of designing each page from scratch, you simply create a Page Template once and reuse it whenever needed.
Creating a Page Template
To create a reusable layout, we will first create a page template and then apply it while creating similar pages.
1. Navigate to Site Menu > Design > Page Templates > Page Templates (the second tab).

2. Click on Create New Page Template. You’ll be prompted to choose between:
- Content Page Template: Allows you to add both fragments and widgets.
- Widget Page Template: Allows you to add only widgets.
Note: If you have already set a header and footer in a Master Page, you can select it here so you don't have to add the header and footer manually each time.
3. For this example, select the Content Page Template since we need to include fragments.
4. Enter a name for your page template.

Once the page template is created, you can drag and drop widgets or fragments that will be common across similar pages.
In this case, we have added two editable fragment fields: Banner and Services, which will be reused on multiple pages.

5. Click Publish to save your page template.
Applying a Page Template
Now, let’s create a page using the page template we just created.
- Navigate to the Site Builder > Pages > Create New Page.
- You will see a list of available page templates. Select the one you created, for example, Demo Page Template.
- Enter a name for the new page.

Now, The page will load with the Banner and Services fragments already added, as they were part of the template.

You can now customize these fragments according to the specific content of the page, and then publish the page.
You can create more pages that share the same layout but have different content.
Updating Page Templates
Sometimes, you may need to update a page template to reflect new design changes or add common elements across all pages using that template.
To update an existing page template:
- Locate the page template you want to update and edit the template.
- Modify the layout, fragments, or widgets as needed.
- You can add new fragments.
- Remove or rearrange existing components.
- Update default content or styling.
After making changes, click Publish to save the updates.
Note: Changes made to a page template do not automatically apply to pages that were already created using the template. Those pages are independent once created, so if you want the changes reflected, you will need to manually edit each page or recreate them using the updated template.
Updating a page template is useful when you want to maintain a consistent look and feel across your site and streamline the creation of new pages with a predefined structure.
Conclusion
Page Templates in Liferay are a powerful way to ensure consistency, save time, and streamline page creation, especially on large or frequently updated sites. Whether you're working with content pages, widget pages, or using master pages for reusable layouts, templates help maintain a clean structure and reduce repetitive work.