Labels

Learn the powerful enterprise adaptable database:

Getting Started With ADABAS & Natural

Sunday, March 31, 2013

Liferay 6.1: Customizing portal_normal.vm


All Liferay themes make use of this Velocity template engine. A template engine is software that is designed to process web templates (in this case files with a vm extension) to produce output web documents. These web documents are mostly HTML or XML files, but it can also be complete different things like CSS or JS files.

Using a template engine also separates business logic from presentation, which gives the maintainability of your source code a boost. This is also known as the MVC software architecture. In the controller section of your web application you can set variables which you can use to display or do other things in the view section of your web application.

1) Run Eclipse.

2) Go to File/New/Liferay Project.

Fill in my-template-1 for the Project name and My Template 1 for the Display name.
Select the Liferay Plugins SDK and Portal Runtime you’ve configured.
Select Theme for your Plugin type.
Click Finish.

3) The project folder is created.

4) Open build.xml.
replace "_styled" with "classic".

5) Create a new folder "template" under _diffs folder.

6) Copy file portal_normal.vm into _diffs/template folder.

7) Replace the line:

#if(!$is_signed_in)
<a href="sign_in_url" id="sign_in" rel="nofollow"> $sign_in_text </a>
#end

With:

#if (!$is_signed_in)
<form action="" method="get">
<input id="sign-in" type="submit" value="Log In" />
</form>
#end

8) Deploy.


Liferay 6.1: Layout


There are two layers of abstraction to generate a portal page in Liferay.

The first layer is with a theme, which generates these components in a tightly coupled way on a page.


The second layer is the layout, a fragment that fits inside a page generated by theme but wraps
the portlets to control how portlets will be arranged on a portal page.

Layouts are usually grid-like structures and are mostly created in HTML tables with rows and columns or CSS-based containers separated by div tags.

Liferay Portal has some built-in layout templates in its release.

These templates are available for administrator or other users with Manage Pages permission to apply individually on a portal page.

1) Log into the Liferay portal as test@liferay.com

2) Go to Manage/Page Layout.


3) Select 2 Columns (50/50) layout template, and then click on Save button
to save the change.

4) Try to add more portlets, e.g Loan Calculator and Currency Converter. Observe the effects.


5) Change the page's layout to use a different layout template. Click on Manage | Page Layout link in the Dockbar area, then click on 2 Columns (30/70) layout template, and then click the Save button to save the change



The layout is a fragment that fits inside a page generated by the velocity file portal_normal.vm of a Liferay theme.

The content area of each portal page consists of a set of portlets wrapped by the layout. This is the second level of abstraction of presentation.

While the theme controls the general visual appearance of a page, a layout is a separate component invoked in a theme to wrap the way portlets are rendered and presented on a portal page.

Different theme and layout template can be applied independently to a portal page during runtime.

However, it is always the combination of one particular theme and one particular layout that works together for the general look and feel of any particular portal page at any particular runtime.

CREATING LAYOUT


1) Run Eclipse.

2) Create New Project.
project name : my-3-column
display name: My 3 Column
select Layout plug-in type
click Finish

3) Check that your  project folder contains:

docroot
-META-INF
-WEB-INF
...my-3column.png
...my-3column.tpl
...my-3-column.wap.tpl
...build.xml

4) Double-click my-3-column.tpl

5) Use GUI editor to arrange the layout.


6) Sometimes, you need to inspect the XML codes. Right-click the tpl file and choose to open as text file.



Liferay 6.1: Creating A Theme



This tutorial uses Eclipse Liferay IDE 1.5.2 .

1) Run Eclipse Liferay IDE 1.5.2.

2) Go to File/New/Liferay Project.

Fill in my-theme-1 for the Project name and My Theme 1 for the Display name.
Select the Liferay Plugins SDK and Portal Runtime you’ve configured.
Select Theme for your Plugin type.
Click Finish.


3) A new project is created.


4) Open build.xml
Notice that by default the theme is inheriting properties from _styled template.



4.1) Change "_styled" to "classic".


5) Open liferay-plug-in-package.properties
Notice that the file contains the information about the theme.


6) Adding custom.css.
6.1) Locate _diffs folder.


6.2) Add a new folder, name it as css.


6.3) Notice that few other folders are automatically generated soon after css folder is created.

6.4) Copy custom.css from docroot/css to docroot/_diffs/css.



7) Edit custom.css
7.1) Open docroot/_diffs/custom.css.
7.2) Edit the background property as follows: #ffffff (white color)


8) Save.
8.1) Deploy.
8.2) If the Theme plugin doesnt appear in webapps folder, you can try installing the war file through the Control Panel. If this method doesn't work, try to hot deploy the war file.

9) Apply the theme.
9.1) In the Control Panel, go to Site Pages.
9.2) The Look and Feel section should display the new theme.


9.3) Click My Theme 1 radio button.

9.4) In the Look and Feel control box, click Save.


9.5) Get success message.


10) Browse the Liferay Portal front page. (http://localhost:8080/web/guest/home)
Notice that the background color of the portal has changed to white.



Liferay 6.1: Understanding The Structure Of Classic Themes



By default, Classic Themes is installed as an initial template for Liferay Portal. This initial template can be further replicated and modified to produce new themes for the portal.

This tutorial requires you to use Windows Explorer to browse the files and folders. For easy referencing, we will use the ROOT folder as the starting folder, which is physically located at liferay-portal-6.1.0-ce-ga1-1\tomcat-7.0.23\webapps\ROOT. (notice that it is spelled in capital letters).




1) Using Windows explorer, locate ROOT\html\themes in the folder of a running Liferay Portal.
Notice the folders:
1) _unstyled
2) _styled
3) classic


3.1) Liferay Portal packages files in _unstyled directory for a basic skeleton theme and files in _styled directory for basic styling for the skeleton theme.

3.2) The Classic Theme defines most of the elements on the page. By studying its files and folder structures, beginners would be able to understand how a theme is developed.

CASCADING STYLE SHEET

4) Cascading Style Sheet defines the appearance of the elements of the page.
4.1) Open ROOT\html\themes\classic\main.css in notepad, you will see the following texts:


4.2) Main.css is a CSS file that imports other stylesheets into a page. It keeps list of files in sequential order. Each files contains styling description of the page elements. If the element description exists in more than one file, the succeeding stylesheet file overrides the preceding stylesheet file, e.g custom.css overrides everything on top of it in the list.

4.2.1) The role of the CSS files are as follows:
- base.css - has the basic styling that applies to the entire portal.
- application.css - styling related elements used in applications (tabs, pickers, ...)
- layout.css - has styling related to layouts.
- dockbar.css - has styling related to the dock bar.
- navigation.css - styles the navigation.
- portlet.css - style the portlet.

- form.css - has styling related to forms.
- extras.css - has styling related to additional elements such as borders and dialogs.
- custom.css - where custom and overriding css should go


5) You can trace stylesheet code using Chrome's Code Inspector.
5.1) Run Chrome and browse the Liferay Portal Front Page.
5.2) Right-Click on any empty area on the page and choose menu item Inspect Element.


5.3) Chrome splits the window into two parts; the top part is the web page and the bottom part is the Code Inspector panel.


5.4) Notice the login link on top right of the page. We will inspect this element.


5.5) Trace the stylesheet code for the Sign In element.
5.5.1) Scroll down the html codes in the code inspector. While the mouse pointer hovers the codes, corresponding elements on the page will be highlighted. Keep scrolling until you notice the Sign In element is highlighted.
5.5.2) The html code defining the Sign In element is actually:
<a href="/c/portal/login?p_l_id=10963" id="sign-in" rel="nofollow">Sign In</a>

5.5.3) Click on the code segment (as shown below). The matching stylesheet is displayed in the adjacent panel under the section Matched CSS Rules. These codes are stored in the file custom.css.







5.5.4) Click on the file name custom.css (as shown in orange rectangle). The file is opened in the Sources tab.




6) Chrome allows you to change the CSS code and subsequently render the changes in the browser window. The changes is just temporary unless you save the stylesheet file.

6.1) Highlight the text 50% as shown in the screenshot.


At the moment the Sign In element is displayed as follows:


6.2) Change the value to 0%, and you will notice the key logo moves up.


6.3) Change the value to 150%, and you will notice the key logo moves down


6.4) You can even change the logo to something else by modifying the background: url element.
e.g change the file name to lock.png .


6.5) By doing this, a beginner would be able to understand how the stylesheet codes affect the page elements display and gradually learn to modify the code by observing the changes via Chrome Code Inspector facility.

6.6) Modifying the codes directly is actually a 'hacking' approach. While it is easy to be carried out, this is not recommended by Liferay creator. A recommended approach is to create a Theme Plugin and deploy it in a proper way. This ensures the theme to be supported by future Liferay versions.

IMAGES

7) Using Windows Explorer, go to ROOT\html\themes\classic\images.


7.1) All of the files and folders contains images that are used for the portal as icons, backgrounds, labels etc.

7.2) You may not need to change all of them. Select the one you feel necessary only.

JAVASCRIPT

8)  Using Windows Explorer, go to ROOT\html\themes\classic\js.


8.1) Open main.js. In a quick glance, the codes suggest that some dynamic actions will be performed based on the parameter values when a page or portlet is loaded.


8.2) Using JavaScript at dynamic effect to the portal page. Advanced user may use this to enhance the portal.

TEMPLATES

9)   Using Windows Explorer, go to ROOT\html\themes\classic\templates.


9.1) *.vm is a Velocity file.  Velocity is a popular template engine for Java web applications.


All Liferay themes make use of this Velocity template engine. A template engine is software that is designed to process web templates (in this case files with a vm extension) to produce output web documents. These web documents are mostly HTML or XML files, but it can also be complete different things like CSS or JS files.

Using a template engine also separates business logic from presentation, which gives the maintainability of your source code a boost. This is also known as the MVC software architecture. In the controller section of your web application you can set variables which you can use to display or do other things in the view section of your web application.

- init.vm - This file load the variables used by other templates.


- init_custom.vm - This file is used to override or store new variables.

- navigation.vm - this file contains the navigation HTML

- portal_normal.vm - this file is the main "index" file that contains the base HTML

- portal_popup.vm - this file contains the box around all portlets.

9.2) *.ftl is a Freemarker file. Freemarker is a template language very similar to Velocity. Starting from Liferay 6.0 Liferay supports also Freemarker templates in themes and Web Content templates. Further reading, https://www.liferay.com/web/mika.koivisto/blog/-/blogs/using-freemarker-in-your-theme-templates.


Liferay 6.1: Installing Portal Themes


Additional Portal Themes can be installed to the Liferay Portal. Portal administrator has three options to install the Theme Plug Ins:

A) Hot Deploy.

B) Plugins/Themes Installation.

C) Online Repository.
- Warning: Plugins Installation will be replaced with Liferay Marketplace in future Liferay releases. Read more about Liferay Marketplace for additional details.




A) HOT DEPLOY PORTAL THEMES
1) Go to http://sourceforge.net/projects/liferay-themes/files/themes/
1.1) There is a list of themes for you to download and try. The themes are developed by wasim117.



2) Download smashing-theme.war from http://sourceforge.net/projects/liferay-themes/files/themes/smashing-theme.war/download.

3) Hot-deploy it.
3.1) While the Liferay Server is up and running, drag the war file into the deploy folder.


3.2) After few seconds, the file will disappear. This indicates that the server has taken the file into the system repository.


4) Log in to Liferay Portal as test@liferay.com

5) Go to/Control Panel.


6) Go to Server Panel, click Plugins Installation.


7) Notice that the new Smashing-Theme Plugin has been added to the list.

B) THEMES INSTALLATION

8) Go back to the previous Sourceforge download page an download ipad theme (http://sourceforge.net/projects/liferay-themes/files/themes/ipad-theme-6.1.0.1.war/download).

9) Continue from Step 7. Click Install More Themes button.

10) You will be forwarded to the install page.
Click Upload File.
Select the war file.
Click Install.

You should get success message.

11) Repeat the previous installation steps again.
Go to Server Panel, click Plugins Installation.
 


12) Notice that the new Ipad-Theme Plugin has been added to the list.

13) Go to Liferay/Site Pages.


14) Notice that towards the bottom of the Look and Feel Section, there is a sub-section Available Themes.

15) Install Ipad Theme.
15.1) Click Ipad radio button.

15.2) Click Save.

16) Browse Liferay Portal front page (http://localhost:8080/web/guest/home).
The look of the site has changed according to the Ipad Theme design.

C) UNINSTALL THEMES

17) In the Control Panel page, Go to Server/Update Manager.

18) Notice that both Ipad Theme and Smashing Theme are in the list.
18.1) Click Uninstall to remove them from the portal system.


18.2) Get success message.


19) Browse Liferay Portal front page (http://localhost:8080/web/guest/home).
The look of the site has changed to the initial default theme.