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
2
votes
3 answers

Getting a structure field value in a display template script

I'm trying to put in place a customized display for my Asset Publisher Entries. I created a Structure with an "image" field (named "main_image") and then, I created a display template to get the entries : <#if entries?has_content> <#list…
Mark
  • 21
  • 1
  • 2
2
votes
1 answer

How to write a java class to be accessed in liferay theme?

I have a Scenario where I have a java class written in JSP and its members are used in that JSP itself. The JSP is part of a liferay portlet. Now, I need to write that class for the velocity template in liferay theme so that I can access it in…
2
votes
1 answer

How to create customized dockbar portlet in liferay6.2?

I am creating a page using Liferay6.2 where i need to have left side menus respective to my page. For that i need something similar to dockbar present in Liferay 6.2. Is it possible to create something like that ? And is it possible to place them …
user2574980
  • 229
  • 1
  • 6
  • 16
2
votes
3 answers

How to check logged user in liferay velocity?

I have a requirement that I have to display sign in url in webcontent, if user not logged in and also need to display if user logged I have to display sign out hyper link. I have searched somewhere got $is_signed_in is for checking user logged in or…
ASR
  • 3,289
  • 3
  • 37
  • 65
2
votes
2 answers

How to obtain Role in Liferay Themes?

How to obtain Role of a logged in User in Liferay Themes? How to check if User belongs to a particular role?
Vikas V
  • 3,176
  • 2
  • 37
  • 60
2
votes
3 answers

Velocity cannot link the CSS file

I am trying to link CSS file in my velocity file but for some reason is not working properly. Any ideas? CSS filename:custom.css velocity file snip code:
JohnRambo
  • 568
  • 1
  • 10
  • 23
2
votes
1 answer

Customizing portal's navigation bar

I want to customize the navigation bar in my theme. I searched for the CSS file that styles the navigation bar in the css directory but I couldn't find it. In the nagivation.vm file, the navigation is declared as follows:
2
votes
1 answer

How to catch NoSuchLayoutException in Liferay Velocity theme when layout not found?

I have the following code in a velocity template theme: #set($currLayout = $layoutLocalService.getFriendlyURLLayout($group_id, true, $currFriendlyUrl)) which throws a com.liferay.portal.NoSuchLayoutException at…
Maria Ioannidou
  • 1,544
  • 1
  • 15
  • 36
2
votes
1 answer

Set session on specific Liferay Web-content Structure

How can I set page session on a specific Web-content Structure so if I assign any page with this specific Structure, it will check if the session is there or not and if not it will ask for password input. The user should then insert the password. In…
2
votes
1 answer

Liferay 6.1 dynamic data list in velocity

I build some custom views for DDL. For text type fields i'd iterate through records and display just like below: $record.getField("field_name").getValue() This won't work for the date field. I presume I should use getRenderedValue(themeDisplay)…
1
vote
1 answer

A lot of Theme APIs stop working in Liferay 6.1 while these APIs working in 6.0 and 5.2

I have a serious issue with Liferay 6.1 themes , I know well about themes in Liferay and theme developer, i was working in Liferay 5.2 and 6.0 with the same way, the same APIs and Calls that written in…
Al-Mothafar
  • 7,949
  • 7
  • 68
  • 102
1
vote
1 answer

Liferay theme upgrade from 5.2 to 6.0?

I have upgraded my liferay 5.2 to 6.0 version with the default theme. Now I want to migrate my custom theme from 5.2 to liferay 6.0. What will be step that I can follow so that I can deploy and upgrade liferay 5.0 theme on liferay 6.0. Thanks.
Sunil Rai
  • 432
  • 8
  • 25
1
vote
1 answer

How to create a sortedmap or treemap in velocity templates in liferay

How do I create a sorted map or tree map in velocity templates using liferay? I am creating a velocity template in liferay portal. I use a HashMap to store some key/value pairs. I am creating a HashMap like this #set ($myHashMap = { 'key1':…
Rajesh Pantula
  • 10,061
  • 9
  • 43
  • 52
1
vote
2 answers

How to create breadcrumb in Velocity Template

I'm trying to create a custom Velocity Template for a banner which includes a breadcrumb but have no idea how to go about it. I've noticed the line which says #breadcrumb() in portal_normal.vm looks like a Velocity macro, but I cannot find the macro…
experimenter
  • 768
  • 1
  • 9
  • 30
1
vote
1 answer

Editing velocity template of Liferay changes not showing or takes a while

I'm currently editing my portal_normal.vm (server/tomcat/webapps/mytheme-theme/templates) testing if I can write on the file and see it on my browser. I tried putting a test comment "" just to see if I can really write on the file. So I…
Pennf0lio
  • 3,888
  • 8
  • 46
  • 70
1
2
3
8 9