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

Liferay Web Content Template : How to find out if image has been set?

I have created a Liferay Web Content Structure and Template. This Structure contains an image that can or can not be set. If the image is not set then I do not want to render an IMG tag. How can I determine in my template if the picture is set /…
Breiti
  • 579
  • 5
  • 21
0
votes
1 answer

Liferay Custom field from web content in velocity template

I need to set some custom tag in portal_normal.vm which define in each Web Content. My case: Go to Control Panel --> custom Field --> web content Create a new custom field called "custom_metas" Put this code in portal_normal.vm
Albertogf
  • 1
  • 1
0
votes
1 answer

Recreating the Liferay jsessionId in a custom theme

I have created links in my theme. Unfortunately those links need to contain something like this : "http://localhost:8080/test:jsessionid=ABCDEFG" . I was able to do this in a journal article using this…
Breiti
  • 579
  • 5
  • 21
0
votes
1 answer

Can't #foreach loop with my simple structure

I'm having trouble looping through the social media links in my repeatable Authors structure. Here is what the structure looks like: The name field for the Authors section is authors and the name field for the social media links is social_media.…
Saad
  • 49,729
  • 21
  • 73
  • 112
0
votes
0 answers

Can't install Veloeclipse for Liferay Developer Studio

I am trying to get syntax highlighting for .vm files in my Liferay Developer Studio IDE, but I am having issues installing Veloeclipse. I went to Help → Install New Software... → Add... For the Name, I entered Veloeclipse and for the Location, I…
Saad
  • 49,729
  • 21
  • 73
  • 112
0
votes
1 answer

Link to page not working liferay 6.2 web content template

I have created a site template in Liferay6.2, in that site template, I have created a structure and template, in that I used link to page. The code for the link to page is as follows: Create…
ASR
  • 3,289
  • 3
  • 37
  • 65
0
votes
1 answer

Liferay velocity template showing only first image for repeatable image field

I have created structures and template for adding the events. The input I have taken is: year with month, image for the event, description for the event. All the data is displaying properly except image. The image which I have given first is…
ASR
  • 3,289
  • 3
  • 37
  • 65
0
votes
1 answer

Calling Java methods in portal_normal.vm

I have a theme realized in Liferay. I have a form portlet on the control panel that the user can fill. Depending on the values inserted in the portlet the theme homepage should appear differently. I was thinking to use something like that but it…
user73793
  • 151
  • 8
0
votes
1 answer

PageUrl from Velocity

I'm creating a theme on Liferay. I have a page for custom searches located in a special page in which the search portlet is contained. I'm using the following syntax in velocity to get the URL of the page but I don't manage to obtain…
user73793
  • 151
  • 8
0
votes
2 answers

Detect first log of user

I'm realizing a theme with liferay using velocity. I would like to add some functions to the theme homepage only in the case the user logs in the portal for the first time. How can I use velocity (portal_normal.vm) to achieve that?
user73793
  • 151
  • 8
0
votes
0 answers

Velocity Liferay Issue in Internet Explorer

I'm running Liferay 6.2 GA2. Created a Web Content with a dummy Structure and Template with the following source. #set($layoutServiceUtil = $serviceLocator.findService("com.liferay.portal.service.LayoutService")) #set($topPublicLayouts =…
Ashok Goli
  • 5,043
  • 8
  • 38
  • 68
0
votes
1 answer

Generate portlet instance id liferay

I'm building some pages in liferay 6.1 GA3, so recently I was in need of embedding liferay web content portlets in an other web content portlet for this I use something like :
wadi3
  • 226
  • 3
  • 13
0
votes
2 answers

Render article with given template in a velocity template

I have defined: A structure Two or mote templates associated to the structure (full content, short block abstract, ...) A web content in the given structure in a different template I have the functions to gather the reference to my article; I wish…
lrkwz
  • 6,105
  • 3
  • 36
  • 59
0
votes
1 answer

Uncaught SyntaxError: Unexpected token ILLEGAL

I work with liferay 5.2 I want to display same message related to the current language of liferay the code of this message is in the velocity lnaguage this is the source code navigation.vm
franco
  • 1,829
  • 6
  • 42
  • 75
0
votes
1 answer

provide a link to navigate to control panel from liferay theme

I am trying to provide a link to navigate to control panel from my theme. I used the following piece of code.
  • Manage Your Profile
  • This worked fine in my local test environment. But when I move this to…
    1 2 3
    8 9