Skip to content

Instantly share code, notes, and snippets.

@farmerbradllc
Last active March 12, 2019 15:14
Show Gist options
  • Save farmerbradllc/04a11b31fabe021db022 to your computer and use it in GitHub Desktop.
Save farmerbradllc/04a11b31fabe021db022 to your computer and use it in GitHub Desktop.
Using Resources Importer to build Demo Site

##Using Resources Importer to build Demo Site

Resources Importer is a tool that Liferay build to contain the raw content files and to be able to consistanly create site content along with a theme. If you have downloaded a 6.2 version of liferay and selected to include sample data, then you've seen the results of the resources importer. The Welcome Theme is included with the bundle: https://github.com/liferay/liferay-plugins/tree/6.2.x/themes/welcome-theme

The Resources Importer is a web plugin for liferay that will take content structured a particular way and create ether a site template or site based on that content.

Useful for Development

Let's say you are working on a Proof of Concept project for a client and there are several team memebers working to build out the site and make sure the Theme and UI work and look great. When developming locally does each team member pass around .LAR exports that may or may not import? Or does each team member pass around a large SQL database and document library images? Or does each member of the team have to manually build out their site pages which might vary from another team members.

If you package the content for the resources importer in source control such as git/svn then everyone can be on the same page for the project. Better yet, include an integration server that will rebuilt the site for each commit on a development server that team shows to the client.

There are some limitations of what the resources importer can do, so to get around those issues, include a groovy script that gets ran when the server rebuilds. For example have the groovy script create some users and some blog posts assigned to several users.

Folder Structure

[theme-name]/docroot/WEB-INF/src/resources-importer

-- sitemap.json (defines the pages, layout templates, and portlets)

-- assets.json (optional) specifies details on the assets

-- document_library/

--- documents/ contains documents and media files

-- journal/

--- articles/ contains web content (HTML) and folders grouping web content articles (XML) by template. Each folder name must match the file name of the corresponding template.

--- structures/ contains structures (XML) and folders of child structures. Each folder name must match the file name of the corresponding parent structure.

--- templates/ groups templates (VM or FTL) into folders by structure. Each folder name must match the file name of the corresponding structure.

sitemap.json

This file is where the site's pages are defined and configured. Edit this file to set up the following:

  • Setting default layout template to use.
  • Place portlets/webcontent on the page.
  • Configure Portlet Preferences.
  • Localize Page Names

assets.json

This file specifies details about the assets to be imported.

  • add tags to documents, web content
  • set Abtract Summary for Web Content
  • Set small image for web content

/journal/articles/

Below shows the relationship between structures and templates by using the folder structure you can define which template to display the structured data. If you want to reference documents in the .html or filled out .xml file use [$FILE=carousel_item1.jpg$] where carousel_item1 is the document located in /document_library/documents/. Note: Only use Documents and Media structure data type when linking an image to the document_library/documents/ folder.

  • Welcome.html
  • /[Template Name]/Home Carousel.xml

/journal/structures/

  • /[Structure Name].xml

/journal/templates/

  • /[Structure Name]/[Template Name].vm
  • /[Structure Name]/[Template Name].xml

Document Library

  • the documents in this folder will be added to the Site Template's document library.

Getting Started

  • Create your theme using the Liferay SDK (ANT) (create.bat theme-name "Theme Name")
  • Modify liferay-plugin-package.properties Add the following:
required-deployment-contexts=\
    resources-importer-web

resources-importer-developer-mode-enabled=true

The developer mode will allow on redeployment for the site template to be deleted and rebuilt to reflect the new changes. Don't create a site using the site template while still developing, you will have to delete the site associated with the template before the site template can be updated.

  • Edit the sitemap.json file

-- "layoutTemplateId": "2_columns_ii" this is the default layout template for your site. To find out the id Edit Page >> then inspect the image of the particular layout remove the .png

{
	"layoutTemplateId": "2_columns_ii",
	"privatePages": [
		{
			"columns": [
				[
					{
						"portletId": "58"
					}
				],
				[
					{
						"portletId": "47"
					}
				]
			],
			"friendlyURL": "/home",
			"name": "Welcome",
			"title": "Welcome"
		}
	]
}

Advanced Configurations

  • This configures the web form portlet's description, fields, portlet title, and adds custom class name, and hides portlet border.
[
	{
		"portletId": "1_WAR_webformportlet_INSTANCE_${groupId}",
		"portletPreferences": {
			"description" : "Lorem ipsum dolor sit amet, lohtil consectetur adipiscing elit. Vivamus feugiat, augue in sollicitudin blandit, magna purus bibendum justo, quisnic scelerisque ipsum turpis eu dui. Nunc lobortis, augue ac viverra convallis.",
			"fieldLabel1": "Full Name",
			"fieldLabel2": "Email",
			"fieldsEditingDisabled": "true",
			"fieldType1": "text",
			"fieldType2": "text",
			"fieldType3": "textarea",
			"fieldValue": "Write your short description here",
			"portletSetupCss": {
				"advancedData": {
					"customCSSClassName": "make-appointment"
				}
			},
			"portletSetupShowBorders": "false",
			"title" : "Seeing your Doctor, made easy"
		}
	}
],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment