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
1 answer

How to add custom meta tag in Liferay generated page

I need do put different META tags in different Liferay generated pages. Example How can I achieve this? Update I cannot be more…
danyolgiax
  • 12,798
  • 10
  • 65
  • 116
1
vote
1 answer

How to fix "class not found exception" while creating dynamic class using velocity template

I have created a template of a class using velocity template and passed dynamic variables to it. It did created a class for me but when i tried to load that class it showed me "class not found exception" as the class is not present in class path. Is…
1
vote
1 answer

How to request JQuery array in Liferay velocity template variable

I have this code in .vm file ..... var attr = attr0[i].id; #set($attr1 = $request.getParameter("attr")) $attr1 How to get the jquery attribute (which is clientside) to velocity template variable which is serverside?
Drozzy
  • 71
  • 1
  • 8
1
vote
1 answer

Liferay velocity Webcontent template - $JournalArticleLocalService

In my Liferay 6.2 EE Velocity Webcontent template i declared the themeDisplay object as follows: #set ($themeDisplay = $request.theme-display) I also adapted my…
HelmutSteiner
  • 99
  • 2
  • 11
1
vote
0 answers

How to hide right caret on dropdown menu liferay 6.2

I have a created a second level submenu on my navbar on Liferay 6.2 I have tried to hide the right arrow caret that is shown always on dropdown menu, when it has a child. You can see it here: https://s10.postimg.org/67vbfzu7d/caret.jpg
fashbio
  • 11
  • 1
1
vote
1 answer

Why aren't Liferay objects rendering in my Velocity template?

A simple example: /* Get user roles */ #set($userId=$request.attributes.get('USER_ID')) #set($roleLocalService=$serviceLocator.findService("com.liferay.portal.service.RoleLocalService")) $roleLocalService.getUserRoles($userId) What renders on the…
mmcglynn
  • 7,668
  • 16
  • 52
  • 76
1
vote
1 answer

utilLocator.findUtil("com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil") is undefined

I am using the below code in ADT custom template code <#assign storageEngineUtil = utilLocator.findUtil("com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil") /> But this is giving …
suresh goud
  • 367
  • 1
  • 3
  • 19
1
vote
0 answers

How to add custom field date-time in ddm structure?

Currently we can add only date in the structure. I want to add time as well. I had tried below link and created simple custom field. …
1
vote
1 answer

How to apply configuration changes of language portlet to all pages

I add the language portlet in my liferay theme using this code: #set ($VOID = $velocityPortletPreferences.setValue('portletSetupShowBorders', 'false')) #set ($portlet_id = '82') #set ($instance_id = "239abc678iuy") #set ($my_portlet_id =…
sedki
  • 25
  • 5
1
vote
0 answers

Liferay 6.2 Search result on separate page

Is it possible to redirect search-Result (portlet: $theme.journalContentSearch() ) to my "http://localhost/search" page? I need this, because on home-page I don't have any portlets-placeholder, and after submit search-form, I see nothing. If I…
user826822
1
vote
2 answers

Site default URL in Liferay with Velocity

I'm using Liferay 6.2 and I would like to get the default site URL using Velocity. Thanks.
wikimix
  • 457
  • 6
  • 23
1
vote
1 answer

alternative liferay theme language

I need to develop a theme and but i don't like velocity, when creating the theme with the maven archetype i saw a property in pom.xml liferay.theme.type and reading about it seems that you especify vm if your templating language is velocity, but i…
1
vote
1 answer

How to handle invalid authentication in liferay sign in portlet

Im trying to customize the login portlet for my purpose using this portlet login sample. But when i login with test@liferay.com with a wrong password it shows "web page is not available" SignInPortlet.java public class SignInPortlet extends…
playmaker420
  • 1,527
  • 4
  • 27
  • 52
1
vote
1 answer

Access custom service class in servicelocator in liferay velocity template

I have a scenario where I have a class and some methods in it which i need to access in liferay velocity template in my theme. I tried accessing the class as a service in my vm file using #set ($myService =…
aayushdriger
  • 382
  • 3
  • 19
1
vote
1 answer

Error while dynamically adding web content filtered by site in custom theme

I am trying to filter the web content according to the site/community name of current logged in user and below code is written in portal_normal.vm. I am using my own custom theme.I have 3 sites in my portal application ,namely,Global…
Mani
  • 283
  • 3
  • 21
1 2
3
8 9