Tag: Liferay

Step by step guide to create a theme in liferay with Angular Material UI

Liferay theme is a collection of files that define the look and feel of a Liferay portal instance. It includes files such as CSS, JavaScript, images, and templates that control the presentation and layout of the portal’s pages, as well as its overall styling and behavior.

Themes in Liferay can be customized and created from scratch to meet specific design requirements, or they can be based on pre-built templates that are available from the Liferay community or commercial sources. They can also be applied to individual sites or globally to affect the appearance of the entire portal.

In addition to providing a consistent and visually appealing user interface, Liferay themes can also improve the accessibility and usability of a portal, enhance its branding and identity, and help to create a seamless and engaging user experience for visitors and users.

What is Angular Material UI and how it can help building a better UI (User Interface) ?

Material UI is a popular user interface (UI) library for building web applications using Angular, a JavaScript library for building user interfaces. Material UI provides a set of pre-built UI components that follow Google’s Material Design guidelines, which is a design language for creating intuitive and engaging user experiences across platforms and devices.

The library includes components for common UI elements such as buttons, forms, dialogs, navigation, and more. It also provides support for responsive design, accessibility, and internationalization.

Material UI can help to speed up the development process by providing a consistent and visually appealing set of UI components that can be easily customized to fit specific design requirements. It is also widely used and supported by a large community, with regular updates and improvements being made to the library.

Here’s an example of creating Liferay theme with Angular Material UI

1. Create an Angular application using the Angular CLI:

ng new my-app

2. Add Angular Material and the Liferay theme dependencies to the Angular project:

ng add @angular/material
npm install --save-dev liferay-theme-deps liferay-theme-tasks

3. Use the Liferay Theme Generator to generate a base Liferay theme for Angular, and select Angular Material as the UI framework:

yo liferay-theme:import --includeAngular --includeJSP --includeSass --framework=material

4. Customize the theme as needed by modifying the Angular code and using the Liferay theme configuration files. For example, you can modify the styles in the _custom.scss file:

@import "node_modules/@angular/material/theming";
@import "node_modules/liferay-font-awesome-web/css/font-awesome.min.css";

@include mat-core();

// Define your custom theme
$liferay-theme-primary: mat-palette($mat-deep-purple);
$liferay-theme-accent: mat-palette($mat-amber, 600, 800, A200);
$liferay-theme-warn: mat-palette($mat-red);

$liferay-theme-theme: mat-light-theme($liferay-theme-primary, $liferay-theme-accent, $liferay-theme-warn);

// Include Material Design icons from the icon font
$md-icon-font-path: "~@angular/material/prebuilt-themes/indigo-pink/"; // adjust path to match your setup
@import "~@angular/material/prebuilt-themes/indigo-pink/prebuilt-themes.css";

5. Use Angular Material’s theming capabilities to customize the look and feel of the UI components. For example, you can change the color scheme of a button:

<button mat-raised-button color="primary">My Button</button>

6. Build the theme using the Liferay theme tasks and deploy it to your Liferay instance:

gulp build
gulp deploy

Note that this is just a basic example and there are many other customization options available for both Liferay and Angular Material. Also, make sure to check the official documentation and best practices for each technology to ensure proper usage.

Liferay 7 DXP Tops Google Trends

Liferay 7 DXP Scale is based on the average worldwide traffic in one year. Awesome!

Recently released Liferay 7 DXP (Liferay Digital Experience Platform) saves the scale of graph in google trends.

Benefits

  • Single, consolidated platform
  • Securely handle private data
  • Easy-to-use interfaces
  • Microservices architecture
  • Easy to integrate and customize
  • Front-end developers can use any popular framework they like (Angular,React)

Liferay trend on google before releasing Liferay 7

Animated layouts in Liferay using Isotope JS

This article will help you to learn and how we can use isotope javascript library in our project. Isotope javascript library who developed by the David DeSandro. Isotope provides animated sorting and filtering in UI elements. It uses Masonry and packery layouts in addition to other layouts.

I found both of them before some days when i started working in one of my project and it’s so amazing, I whipped up a few demos to see for myself!

Install Isotope

For installation we need to download these isotope library from isotope website.

  • isotope.pkgd.js un-minified, or
  • isotope.pkgd.min.js minified

Package managers

  • Install with Bower: bower install isotope –save
  • Install with npm: npm install isotope-layout

Configuring Isotope

Portal_nirmal.vm

Include the Isotope .js file in your Theme.

<script src="${themeDisplay.pathThemeJavaScript}/isotope.pkgd.js"></script>

 

After create a theme you can create a portlet with the name of isotope-layout for writing your HTML. write initialization code in your theme main.js file.

Initializing isotope with Jquery:

$('.isotope-grid').isotope({
  // options
  itemSelector: '.items',
  layoutMode: 'fitRows'
});

Initialize with Vanilla JavaScript:

var elem = document.querySelector('.isotope-grid');
var iso = new Isotope( elem, {
  // options
  itemSelector: '.items',
  layoutMode: 'fitRows'
});

// element argument can be a selector string
//   for an individual element
var iso = new Isotope( '.isotope-grid', {
  // options
});

Initialize in HTML:

You can initialize Isotope directly in HTML, without writing any JavaScript or Jquery. You have to just add js-isotope to the class of the container element. For adding the options you can add data-isotope-options attribute in your element.

How to use Filtering,Sorting and Layout

Using Isotope you can hide and show item elements with the filter option. Which shows the only matched items according to the filter. Here you can see how we can apply the filters on:

Selectors(Like Class and id)

$grid.isotope({ filter: '.ClassName' });

jQuery selectors(if jQuery is present)

// filter .ClassName items that are NOT .transition class

$grid.isotope({ filter: ‘.ClassName:not(.transition)’ });

With Functions

$grid.isotope({
  // filter element with numbers greater than 50
  filter: function() {
    // _this_ is the item element. Get text of element's .number
    var ClassName = $(this).find('.ClassName').text();
    // return true to show, false to hide
    return parseInt( ClassName, 10 ) > 50;
  }
})

UI with Buttons

<button data-filter="numberGreaterThan50">number > 50</button>
<button data-filter="ium">name ends with -ium</button>
// init Isotope

var $grid = $('.grid').isotope({
  // options
});

// filter items on button click

$('.filter-button-group').on( 'click', 'button', function() {
  var filterValue = $(this).attr('data-filter');
  $container.isotope({ filter: filterValue });
});

Sorting

In Sorting we are using two methods getSortData() and SortBy().

For more Information: Sorting

layout

In Layout all sizing and styling of items is handled by your own CSS so when we are developing the responsive layouts then we need to set item sizes with percentages in css and also we need to change the mode of layout with masonry and set the percentage-width columnWidth with element sizing. Setting up the percentPosition option true (percentPosition: true) reduce the adjustment transitions on responsive mode.

For more Information: Layout

Getting started AngularJS with Liferay Portal

After reading the title of this post the first question comes in your mind is “Can we use AngularJS with Liferay?”
and my answer is yes we can. Now your thinking why AngularJS? I will give the answer of your all questions in this article.

What is AngularJS?

Angular js is open source web application development framework developed by Misko Hevery and maintained by Google. AngularJS architecture based on MVC(Model – View – Controller). MVC pattern help you to manage separately presentation, data, and logic components. server-side services are offered by Angular, like view-dependent controllers, to client-side web applications.

These are the some remarkable features:

  • HTML Declarative approach:This feature help you to declaring dynamic views in static web-applications. For your application, AngularJS facilitates you to extend HTML vocabulary. The consequential ssetting is especially expressive, readable, and quick to develop.
  • Easy Data Binding : AngularJS Two-way data binding is its most distinctive feature, and it reduces the amount of write dynamic code.
  • Reusable Components: Using AngularJS directives help you to make your component reusable.
  • Dependency Injection: You can easily inject dependencies of other modules in your web Application. Dependency injection is also a core to AngularJS.
  • End to end Integration Testing / Unit Testing: While writing a code for application, we also need write test cases. Angular is designed makes testing your application easy by using dependency Injection feature that makes testing components much easier then any other frameworks. Jasmine and Karma are the testing tool which we use in angular application
  • Routing: This feature allows to make your SPA website much easier.
  • Templating: Dynamically creating and updating HTML based on templates.
  • Services: you can use server side services in angular to make your web application dynamic.

If you are thinking to develop Angular Web Application in LIferay Developer Studio then Before starting to write a code you must know how to configure AngularJS in your liferay. It’s reduce your efforts to develop and maintain your Angular Web Application in Liferay. You can also write individual portlet in AngularJS. So in this article i am going to make a Independent News List portlet with the help of JSON Array in Angular.

Creating a liferay portlet

  • Go to the package Explorer > Right click New > Select Liferay Plugin Project

See Figure 1
Angular-porlet

If you want to setup AngularJS in Liferay developer studio. Read this article

or you can directly add the AngularJs Library in your theme or You can add directly in your portlet as well.

  <script src="${themeDisplay.pathThemeJavaScript}/lib/angular.min.js"></script>

Now start write your code in portlet main.js file.

In this article you can see how Angular makes browsers intelligent— without the use of any other third party plugins.

What you Learn in this article:-

  • Examples of how to use client-side data binding to build dynamic views of data that change immediately in response to user actions.
  • See how Angular sync your data in view without the need for DOM manipulation.
  • Learn a better, easier way to create AngularJS based portlet that works independently with your application

Getting Started

AngularJS is using HTML Declarative Approach to write and extend HTML code with custom attributes and elements. It’s also helps you to in Data Binding. You have to create one pure static HTML page then examine how we can convert this HTML code into a template that angular will use to display dynamic data.

So here is Static HTML code:-

<ul>
		<li>
			<a href="#"><img src="" alt="news-img"/></a>
				<div class="news-desc">
					<h4></h4>
					<p></p>
				</div>
			</li>
			<li>
			<a href="#"><img src="" alt="news-img"/></a>
				<div class="news-desc">
					<h4></h4>
					<p></p>
				</div>
		</li>
	</ul>

In AngularJS, the view is a magnification of the model through the HTML template so whenever we change anything in the model angular refreshes the same binding points and updates in the view.

The view component is frame by Angular from this template:

docroot/view.jsp:

<div ng-app="NewsListApp" class="NewsListApp">
	<ul ng-controller="NewsListCtrl">
		<li ng-repeat="news in newslist">
			<a href="{{news.url}}" class="news-img">
				<img src="{{news.img}}" alt="news-img"/></a>
				<div class="news-desc">
					<h4><a href="{{news.url}}">{{news.title}}</a></h4>
					<p>{{news.desc}}</p>
				</div>
			</li>
	</ul>
</div>

We replaced the HTML news list with the ngRepeat directive and Angular expressions:

  • The ng-repeat=”news in newslist” attribute in the
  • tag is an Angular repeater directive. The repeater tells Angular to create a
  • element for each news in the list using the
  • tag as the template.
  • The expressions wrapped in curly braces {{ }} will be replaced by the value of the expressions.

We have added a new directive, called ng-controller, which attaches a NewsListCtrl controller to the parent tag.

  • The expressions in curly braces {{ }} show bindings, which are referring to our NewsListApp model, which is set up in our NewsListCtrl controller.

Now Build your portlet. After completing successful build go to your browser open your localhost site and just drag the portlet in layout to see the result.

Note: We have specified to load Angular Module using ng-app=”NewsListApp”, where NewsListApp is the name of our module. This module will contain the NewsListCtrl.

Theme Development in Liferay

LiferayUI blog will help you make you own theme to customize your liferay’s portal appearance and impression. With themes, you can alter the user interface completely that it becomes difficult yet impossible to identify that the site is running on Liferay.

Liferay’s theme inherits the styling, images, and templates from any of the built-in themes. This saves your time and keeps your themes smaller and less cluttered, because your theme contains only its own resources, using defaults for the rest, like Templates,Js,Images and CSS.

Theme Development in liferay is easy to create. You can start by making changes in the CSS files. When you need to customize themes more extensively, you can change the HTML Templates.

If you hope to become a Liferay theme development and customization expert, there are several technologies you should know:

  • CSS: Create a new theme simply by modifying a CSS file.
  • Velocity: Customize the markup generated by the theme.
  • JavaScript: Add special behaviors to your theme.
  • XML: Some theme settings are specified in XML.

Creating a Theme

Our theme will be named HM Blue, so the project name (without spaces) is hm-blue, and the display name (which can have spaces) is HM-Blue. Let’s create the theme using Liferay Developer Studio first, and then with the terminal (Command Prompt).

Using Developer Studio:

  • Go to File → New → Liferay Project.
  • Fill in HM-blue for the Project name and HM Blue for the Display name.
  • Select the build type, Plugins SDK, and Liferay runtime.

See this link if you Using Liferay IDE with Maven for more information. Otherwise, select the Ant build type.
For more information, see sections Installing the SDK and Setting Up Liferay IDE.

Select Theme for your Plugin type.

Click Next.

Theme-Creation

Figure 1 : Make sure to select the Theme plugin type for your theme.

Setting a base Theme

Now you have to Select a theme parent. In Liferay you have two base theme, all themes are built on the top of it, which is assign style and unstyled. Your newly created theme is based on these by default, but they contain very limited styling. You can take advantage of an existing theme’s styling by setting the theme of your choice as the base for your theme. styled theme providing the most basic elements. When you set a different base theme, it’s added on top of styled and overrides the default styling wherever there are differences. After the base themes are added, your own custom styling is affixed on top.

select-framework
Figure 1.1 : Make sure to select the Theme plugin type for your theme.

By Default it’s select _styled theme. Adding together in to the _styled theme, from the unstyled theme you can select the inherit, which includes no styling. There’s also the classic theme that has a smooth look and feel and works well. For now, select _styled as the theme parent.

Select your theme’s framework. You can select the Freemarker or Velocity template frameworks for your theme. Or you can select JSP as your theme’s framework. For now, select _Velocity framework template framework. See figure 1.1

Click Finish.

To specify a base theme, edit the build.xml file for your theme and change _styled in to the name of any existing theme that’s installed or in your Plugins SDK. Now that your base theme is set, let’s deploy the theme to your portal instance.

Theme Deployment

If you’re already familiar with portlet deployment then theme deployment will be a piece of cake! You can deploy your theme in Developer Studio or the terminal (Command Prompt).

Deploying in Developer Studio: Click and drag your theme project onto your server.

Theme-Deploy

After deploying, your server outputs messages in console to indicating your plugin is available for use.

  • Reading plugin package for hm-blue-theme
  • Registering themes for hm-blue-theme
  • 1 theme for hm-blue-theme is available for use

Let’s apply your theme to a page:

  • Go to your web browser and log in to the portal.
  • Hover over Manage at the top of the page and click on Page.
  • Directly underneath the words Manage Pages, select the Look and Feel tab. Click on your theme to activate it.

Redploy

Now that you’ve built and redeployed a theme, let’s see the hierarchy of theme.