Book Image

Liferay User Interface Development

By : Jonas X. Yuan, Xinsheng Chen, Frank Yu
Book Image

Liferay User Interface Development

By: Jonas X. Yuan, Xinsheng Chen, Frank Yu

Overview of this book

<p>Liferay employs a specialized theming system, which allows you to change the look and feel of the user interfaces. As a developer, by using the right tools to create and manipulate themes with Liferay Portal, you can get your site to look any way you want it to; but the Liferay theming system can be difficult to get started with. This practical guide provides you with a well organized manual for working with Liferay as a programmer to help you get started.<br /><br />Liferay User Interface Development is a pioneer in explaining Liferay's powerful theming system by taking you through examples to get you to create your own themes as quickly as possible. It focuses on how portal pages are created and styled and also discusses some simple configuration and customization to change the look and feel of a portal page. Its explicit instructions are accompanied by plenty of source code. With the open source nature of Liferay, you will find a user-friendly environment to design themes with the latest user interface technologies.<br /><br />Liferay User Interface Development unlocks the potential of using Liferay as a framework to develop a rich user interface.</p> <p>The book starts off with how you should go about structuring a Liferay Portal web page. It identifies the components of a portal page: theme, layout, and portlets. This hands-on tutorial explains themes, portlets, and Alloy UI, which is the latest output from the Alloy Project of Liferay, in an easy-to-understand way. It covers all aspects of a theme from its inception and rendering through its consumption by an end user, with in-depth discussion.<br /><br />By the end of this book, you will clearly understand themes, layouts, and the Alloy API. Most importantly you will obtain the skills to write a theme and layout templates, apply them to a portal, and also control the portlet UI through different mechanisms.</p> <p>This clear, concise, and practical tutorial will ensure that you have developed skills to become a competent Liferay themer. The detailed text is accompanied with source code that allows you to play with the examples, update the code, and add custom features.</p>
Table of Contents (12 chapters)
11
Index

Customizing user interface through themes development framework

A theme specifies styles of all major global portlets and content, so it controls the way the portal will look. In general, a theme uses CSS, images, JavaScript, and Velocity (or FreeMarker) templates to control the whole look and feel of the pages generated by the portal. Therefore, when creating customized themes, we need to consider these four groups as well. The theme is made up of a folder _diffs with four subfolders css, images, javascript, and templates; and a folder WEB-INF with the properties file liferay-plugin-package.properties and, optionally, XML file liferay-look-and-feel.xml.

  1. As shown in the following figure, when you deploy a theme, it will copy all files from the folder ${app.server.portal.dir}/html/themes/_unstyled/ to the folder $PLUGINS_SDK_HOME/themes/${theme-name}/docroot/ first. In fact this will happen during build time, instead of deploy time.
  2. All files from the folder ${app.server.portal.dir}/html/themes/_styled/ are copied to the folder $PLUGINS_SDK_HOME/themes/${theme-name}/docroot/, too.
  3. Later, it will copy all files from the folder $PLUGINS_SDK_HOME/themes/${theme-name}/docroot/_diffs/ to the folder $PLUGINS_SDK_HOME/themes/${theme-name}/docroot/. It means that you will override existing files with new files and changed files under the folder $PLUGINS_SDK_HOME/themes/${theme-name}/docroot. Here the ${theme-name} refer to a real theme project name.

Then, you will see four folders such as css, images, javascript, and templates under the folder $PLUGINS_SDK_HOME/themes/${theme-name}/docroot. And each folder will contain all merged files and subfolders from /_unstyled, /_styled, and /_diffs.

Customizing user interface through themes development framework

Build differences of themes

The best practice of building customized theme is to put only the differences of customized theme into the folder ${theme-name}/docroot/_diffs. Here ${theme-name} refers to any theme project name such as, for example, book-street-theme. Using the best practice, we need to put customized CSS, images, JavaScript and templates in the folder /_diffs only.

In the folder /_diffs/css, create a CSS file custom.css. We should place all of CSS that is different from the other files. By placing custom CSS in this file, and not touching the other files, we can be assured that the upgrading of their theme later on will be much smoother. In the folder /_diffs/images, put all customized images with subfolders. For example, create two images: screenshot.png and thumbnail.png, to record what a page with current theme looks like. And furthermore, create a subfolder searchbar, and put all search-related images in this folder /searchbar.

In the folder /_diffs/javascript, create a JavaScript file javascript.js. Liferay portal includes the YUI Library. Thus in the theme, we can include any plugins that YUI supports. In the folder /_diffs/templates, create customized template files (for Velocity, it is *.vm files; for FreeMarker, it is *.ftl files), such as dock.vm, init_custom.vm, navigation.vm, portal_normal.vm, portal_pop_up.vm, and portlet.vm. Note that you can use JSP files in template files under the folder templates. However, you won't have access to the velocity variables if JSP files were in use.

Developing user interface through layout templates development framework

Layout Templates are ways of choosing how portlets will be arranged on a page. Layout templates are usually a grid-like structure, and most often, are created with HTML tables. They make up the body of page, the large area where portlets are dragged and dropped to create pages. In a word, a layout template describes how various columns and rows are arranged to display the portlets. In brief, layout template controls the visual structure of pages in the portal.

As shown in following figure, the Plugins SDK provides an environment for developers to build layout templates, similar to that of portlets and webs. It uses the Ant target Deploy or Maven to form WAR file and copy it to the Auto Deploy directory first. Then the portal will detect if there are any WAR files in the auto hot-deploy folder, and automatically extract the WAR files into an application server deployment folder.

Developing user interface through layout templates development framework

Note that both WEB and WAP got supported in layout templates. A layout template plugin should include at least two files: a file called .tpl for WEB and a file .wap.tpl for WAP. The WEB version specifies the arrangement of portlets in a page in web browsers; while the WAP version specifies the arrangement of portlets in a page of WAP devices.