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

how to resolve Uncaught TypeError: Object # has no method 'corner' in jquery?
I am using jquery round corner plugin in lifray theme in order to add round corner functionality in all kind of browsers, including IE6 to IE8. i have included the jquery round corner plugin in portla_normal.vm like this :- …
ASR
  • 3,289
  • 3
  • 37
  • 65
0
votes
2 answers

How cleared issues in the issues.liferay.com can be applied in our Liferay Portal

I want to know how to apply the issue changes done in the Liferay Issues can be applied in our portal. For example my issues are cleared in the following…
MKD
  • 799
  • 2
  • 11
  • 15
0
votes
1 answer

How to get image using structure and template to get title,small and large image

I am using liferay 6.1.20. Structure variable demo_image : type Document and Media here is my template code. It is not fetching uuid or groupId from url ! #set ($dlLocalService =…
Hiral
  • 195
  • 1
  • 13
0
votes
2 answers

Check if custom Attribute has value true

I followed this guide to create a Custom field in Liferay. I have created a true/false attribute, but i want to check if this attribute is true or false, if is true get to the menu/Page a cssClass. I tried with this: #set ($menu =…
Mustapha Aoussar
  • 5,833
  • 15
  • 62
  • 107
0
votes
1 answer

portletURLFactory.create does not work in liferay VM

I'm trying to create a link in a Liferay template using Velocity. My code is the following, based on several examples on the net: #set ($plid = $getterUtil.getLong($request.get('theme-display').get('plid'))) #set ($u =…
ttamas
  • 192
  • 1
  • 2
  • 15
0
votes
3 answers

liferay change page title dynamically

I'm trying to change the title of the page, but the method PortalUtil.setPageTitle("title", request); is not working from the jsp. I also tried in the doView method. My second attempt was throught servletrequest: In doView I…
Antonio mc
  • 85
  • 1
  • 12
0
votes
1 answer

Send parameter from Portlet doView to portal_normal.vm

I'm trying to send a parameter from Portlet doView function to portal_normal.vm Is it possible? How can I send and receive it? Sorry, but I can't see the way to do through request. In doView I wrote HttpServletRequest httpRequest =…
Antonio mc
  • 85
  • 1
  • 12
0
votes
2 answers

Loading dynamic theme liferay

There are two themes, I want to change dynamically from portal_normal.vm or from java in doView function. is it possible? I have two domains with only one portal and I want to change depending url.
Juan
  • 83
  • 1
  • 8
0
votes
1 answer

Liferay : Any one has updated jquery.tweet.js?

Has any one used and updated jquery.tweet.js for liferay 6.1 after following important note from seaofclouds.com, Important note about Twitter's API changes Twitter has discontinued its unauthenticated v1.0 API, so this widget has stopped working…
Hiral
  • 195
  • 1
  • 13
0
votes
1 answer

How to make Liferays VelocityVariables accessable for Intellisense in IntelliJ 12

i've our Liferay web content templates (.vm) in a IntelliJ-12 project and want to make the VelocityVariables accessable in the Editor, so some code like this: #set ($portalURL = $getterUtil.getString($request.attributes.CURRENT_COMPLETE_URL)) knows…
kidata
  • 165
  • 1
  • 2
  • 15
0
votes
1 answer

Pass Data to template files in liferay

I would like to pass data such as navigation items or languages supported to the portal_normal.vm file so that it gets displayed on the portal. I don't have a clue about how to do it. I've seen that in velocity files the data is passed in variables…
Marwan Tushyeh
  • 1,505
  • 4
  • 24
  • 47
0
votes
1 answer

Liferay : saxReaderUtil Results

While fetching results from Liferay web content articles, using SAX reader and Velocity , the number of results is limited to…
wikimix
  • 457
  • 6
  • 23
0
votes
1 answer

Decoding html encoded character in velocity liferay

As title, I have an encoded String that I got from my URL, I want to display to user but don't know how to decode it T%E1%BB%87p t%E1%BA%A3i l%C3%AAn => Tệp tải lên I'm using liferay 6.1 ga1, and try to create some webcontent template.
user1487380
  • 362
  • 2
  • 9
  • 26
0
votes
1 answer

How to get value and text of item selected in liferay's web-content velocity template?

I have structure with 1 Selection List and 1 Multi-Selection List
user1487380
  • 362
  • 2
  • 9
  • 26
1 2 3
8
9