Questions tagged [liferay-velocity]

They are mostly used to either 1)Create web content in liferay in conjunction with structures to parse user populated data from structure fields and present it in a view form,using the business logic,or 2)Create theme template file for creating a skeleton structure for themes

Velocity templates are widely used in liferay themes and dynamic web content. They allow us to segregate data(provided by user in fields retrieved from structures) and business logic which is coupled with presentation layer in template. Liferay provides various variables which can be directly used to access objects available in liferay. Service layer of liferay(along with custom user services) can be accessed within a template using serviceLocator.

Usage:

To access an element from structure with name as 'image':

<img src=$image.getData()/>

where '$' is used to access an element while getData() used to access data from the element

To use conditional statements:

#if($permissionChecker.getUserId()==10198)
    $text.getData()
#end 

We can use conditional logic(if,if-else,if-elseif) to check for a particular condition and use any of the default available object variable 'permissionChecker' for condition

To use loops to iterate through siblings or children of an elements:

#foreach($currentText in $text.getSiblings())

    $currentText.getData()

#end

We can iterate through the repeatable elements or other elements in a structure by using a looping statements for the same.

To use service locator to access liferay/custom services

#set($userLocalService = $serviceLocator.findService("com.liferay.portal.service.UserLocalService"))
#set($user = $userLocalService.getUserById(10198)
$user

We can use serviceLocator to access Liferay/custome service in a velocity template and use methods from the same.

#set ($customPortletLocalService = $serviceLocator.findService("custom-portlet", "com.liferay.custom.service.CustomPortletLocalService"))

Further reference links:

1.Using structures and templates in Liferay

2.Java World:Using velocity Engines

134 questions
1
vote
4 answers

Check current page url contents in liferay velocity template

I am trying to find out current page url contents and parameters in liferay Velocity(vm)file. I am able to get current page url by this way. I have tried to decode url …
Java
  • 2,451
  • 10
  • 48
  • 85
1
vote
3 answers

CSS to Liferay theme

I have a css web design and I want to converted in Liferay theme. Is this possible? I am using Liferay 6.1 Ga2 with Tomcat 7 and Liferay SDK for java. Any advice will be appreciated! Thanks in advance
JohnRambo
  • 568
  • 1
  • 10
  • 23
1
vote
1 answer

How to show site page urls in Liferay jsp portlet?

I would like to show some site page urls in a Liferay jsp portlet. I'm using Liferay 6.1 EE. I would like to use page's localized title and other custom fields added (e.g. cssClass). I have done the same for the navigation bar, for my velocity…
Maria Ioannidou
  • 1,544
  • 1
  • 15
  • 36
1
vote
4 answers

Setting the "title" attribute of main menu link items (or page names)

I'd like to have tool tips when I mouse over the main menu items in Liferay. By default, there is no way to do this. Even in the *.vm files, the mark up does not include any title attribute for the links. The way I'm trying to go about it is to have…
Gaurav Sharma
  • 4,032
  • 14
  • 46
  • 72
1
vote
1 answer

Converting string to date with Velocity Template Language in Liferay 6 GA2

I'm having trouble converting a string to a date object in a Liferay 6 GA2 web content template. I've tried my hand using the tools available ( Access Objects in Liferay ) I've even tried importing Java classes like: #set ($foo = "2012-12-06") #set…
cp3
  • 2,119
  • 2
  • 22
  • 27
1
vote
2 answers

Cannot pass PortletSession to CustomUtil from Portlet Velocity templates

I have checked on Using custom services or liferay services in liferay themes (velocity templates)? and Custom Methods are working fine as they are. But I have some specific requirement. Please let me know if you know how to pass PortletSession…
AlexHalkin
  • 1,088
  • 14
  • 33
1
vote
2 answers

Liferay - Obtain filesize in template

Is it possible to obtain size of a file from document library in velocity template? I have a content structure with repetitive files and a very simple template, like below: #foreach($f in $file.siblings)
dotintegral
  • 918
  • 1
  • 10
  • 23
1
vote
1 answer

Main nav items sharing child pages in Liferay 6.1?

FYI, I'm new to Liferay so please have patience with me! Here's the scenario: I have a main nav menu working in my navigation.vm. I've determined that two of the main nav items would share the same child menu listing the same pages. I've gone into…
max7
  • 800
  • 2
  • 16
  • 37
1
vote
1 answer

Sorting items in a Dynamic Data List template in Liferay

I'm experimenting with Dynamic Data Lists in Liferay 6.1. The data definitions and list editors work fine, but I'm having trouble preparing a template to display the list. In particular I'm wondering how to implement sorting and pagination of the…
postrational
  • 6,306
  • 3
  • 22
  • 27
1
vote
1 answer

New structure field is not empty

I'm changing my liferay velocity template by adding new field for structure. e.g. 'heading1' and then adding this new field to template:

Heading is: $heading1.data

But if the structure field is not yet filled the outcome is: Heading is:…
Algeron
  • 269
  • 1
  • 5
  • 16
1
vote
1 answer

Liferay 6.1 Zenlike Theme

I am using Liferay 6.1 CE bundled with tomcat, I deployed the Zenlike Theme (http://sourceforge.net/projects/lportal/files/Liferay%20Plugins/6.1.0%20GA1/zenlike-theme-6.1.0.1-ce-ga1-20120106155615760.war/download) to use it in my portal. My…
0
votes
1 answer

How do I list communities to "logged" out users in Liferay 6?

im trying to create a community select box to enable visitors to jump to open Liferay communities. However it only seems to work for authenticated users. So how I can list 'open' communities to all users including logged out users? Here's my current…
experimenter
  • 768
  • 1
  • 9
  • 30
0
votes
1 answer

How to find web contents with specific structure field value?

I was wondering if anyone could give me some ideas/snippets on how to create Velocity template to loop through Web Content items for a specific structure , and render the contents based on the value of a specific structure field?
experimenter
  • 768
  • 1
  • 9
  • 30
0
votes
1 answer

How can I make Liferay login portlet redirect to maximized version to display validation errors?

I've got a theme which has a login portlet embedded in the header and I dont wish for validation messages to appear on this login portlet, instead I want Liferay to redirect to the maximized version of the login portlet with the validation…
experimenter
  • 768
  • 1
  • 9
  • 30
0
votes
1 answer

Liferay $serviceLocator.findService("com.test.Foo") in portal_normal.vm giving NoSuchBeanDefinitionException

I'm using liferay6 and trying to access com.test.Foo (added to ext-service) in portal_normal.vm using #set ($mySvc = $serviceLocator.findService("com.test.Foo")) I'm getting the following exception. Caused by: …
1 2 3
8 9