Add Page Fragment using SiteInitializer in Liferay 7.1/dxp
June 21, 2019
You’ve from the blank site, community site but it’s looking pretty empty at the moment. You need some default content to go with it, so it looks nice when it’s first installed. Liferay resources importer is a tool that allows files and web content automatically imported into the site when a theme is deployed but the resources importer is deprecated as of Liferay Portal CE 7.1.
The Site Initializer does this for you. Liferay's Site Initializer module is a tool that allows having fragments and web content automatically imported into the portal when a site is created. You can use Fragments to create rich content in Liferay. Fragments are built using HTML, CSS, and JavaScript.
Here I’ll show you how you can create the Site Initializer. The Site Initializer module will import fragments and web content with a site. Administrators can use the site created by the Site Initializer.
Prerequisite:
Basic knowledge about Liferay Theme, Fragments. For more information, Please go through Liferay documentation for how to create Fragments. Creating Fragments
Step 1 - CREATE A LIFERAY MODULE PROJECT.
Step 2 - ORGANIZING YOUR RESOURCES
In order to import fragment with the Site Initializer, you’ll need to create the proper directory structure as described in the image.
Step 3 - DEFINING ASSETS FOR THE SITE INITIALIZER
You must create a fragment to import with your site. Fragments are building blocks that you can use to create rich content in Liferay.
Create an HTML file the fragments package and add your content in this file. You can add style using CSS and JavaScript files in same name .css and .js file.
Here I’m creating Welcome.html file. If I need to add CSS and JavaScript then I have to create Welcome.css and Welcome.js file.
You can also embed widgets and provide fields with editable text and images. The text can be edited during the final Content Page publication process.
Please go through Developing Fragments to get full information.
Step 4 - CREATE A COMPONENT FOR THE SITE INITIALIZER
Create a class and implement SiteInitializer. This class specifies the site pages, page template, layout templates, fragments, web content, look and feel, logo, assets, and portlet configurations provided with the site. This class describes the contents and hierarchy of the site template.
Create Fragments
Override initialize method and create collection because the collection is needed to create fragments. Here I’m creating the collection with the name “Surekhatech”.
Add all fragments of files in the collection. Here I'm creating a “Welcome” fragment in the collection.
We use cookies to deliver personalized content, analyze trends, administer the site, track user movements on the site, and collect demographic information about our user base as a whole. Accept all cookies for the best possible experience on our website or manage your preferences.
What For?