Structures and Templates in Liferay

Structure:

1.Take a scenario that I want to display image in web content portlet dynamically, when I want display image I need image url and need to specify the image width and height. So here our structure will provide required data like image url, height and width of the image to display image . Each time we will fill image url and width and hight dynamically with the help of structure.
2.Structure is simple xml data source which will provide dynamic data to template.
3.In single word we can say structure will decide what kind of data we are going to use and template will decide look and feel for data.

Template:

Template provides look and feel for the structure.we can use html,css and jquery also for look and feel.
Example: Each human look(template) different even though every human skeleton(structure) is same.

How to create structures and templates in Liferay?

1.Goto control panel---->choose webcontent----> create Structure and choose structure while creating template.
2.Last add webcontent portlet into the page, then choose structre and template for the webcontent.
First we have to create structure and then templates.

How to create Strucutre?

To create structure first we need specify what type of data we are passing to template. For example if i want to display image on to the page, first i need to choose type as image or image_gallery. Structures can be created in 2 ways in liferay
1. Directly adding structure code in launch editor.
Example:

2. In XmlSchema definition choose add row, then specify the name and type, is the data is repeatable or not,etc.

How to retrieve the data from the structure in templates?

Example:
1. Structure:
In the below structure i have taken different types of elements:
here type specifies data type we are using.
For example if i want to access display imag from image gallery i have to choose type as image_gallery.To access image from desktop use type as image.To access document from documents and library e choose type as document_library.etc

To access above data in template:

When we select any document or image it will display only url if we use .getData(), to display image we place the url in image tag
syntax:
$elementName.getData()

2.Template:

$doclib.getData()
$textbox.getData()
to access text_box value in template.
$text.getData()
to access text in template.
The dynamic element "main-text" can be accessed in the following ways:

In Structure:

 In template:

$main-text.getName() - The name "main-text"
$main-text.getData() - The data in the article for main-text
$main-text.getType() - The type "text-area"
$main-text.getChildren() - A collection with two nodes (sub-image and sub-text) that can be used in
the #foreach clause
$main-text.getSiblings() - A collection of elements with the name "main-text". This will only return
more than one element if this element is repeatable.

Repeatable data example :

Template:

In templates we can get the siblings like this:
#foreach($e_url in $image_url.getSiblings())
$e_url.link.getData()
$e_url.text.getData()
#end

Search This Blog

All the rights are reserved to this blog is belongs to me only.. Powered by Blogger.