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

Choice of technical solution to handling and processing data for a Liferay Project

I am researching to start a new project based on Liferay. It relies on a system that will require its own data model and a certain agility and flexibility in data management as well as its visualization. These are my options: Using Liferay Expando…
Pymoo
  • 127
  • 1
  • 4
  • 11
0
votes
1 answer

How to create a disclaimer page as default landing page in liferay portal?

My requirement is that after successful login into the portal user should redirect to a page containing company's terms and conditions text with an "Accept" Button. User must click on the Accept button if he wants to access the application. Without…
0
votes
1 answer

how to delete a cookie in liferay DXP custom theme using freemarker?

I want to delete a cookie USERID in my liferay custom theme free marker templete i am using liferay DXP I tried this code <#if !is_signed_in> <#assign aCK=objectUtil("com.liferay.portal.kernel.util.CookieKeys") /> <#assign userID =…
0
votes
1 answer

Liferay 6.2 - (VM) Velocity template for asset publisher - how to get a variable that it is inside another variable?

I am designing a new template for my asset publisher to get all contents with a class com.liferay.portlet.journal.model.JournalArticle from a specific site. In my web content structure i have: -Image inside this image: -there is tow Text variable…
Mohammed Alawneh
  • 306
  • 9
  • 22
0
votes
1 answer

Creating VM theme in Liferay 7

I want to create VM theme in liferay 7. I made the changes in package.json and changed the templateLanguage to vm. Next I changed liferay-look-and-feel.xml and changed tag value to cm and did gulp build. The vm files are created, but when i Deploy…
User14141111
  • 355
  • 2
  • 19
0
votes
0 answers

When I do document preview it will logout first time?

I have liferay open office integration. My problem is when I preview any document after login first time it is logout and ask to login again. Next time it is working fine the problem persist while document preview generation and after user log first…
0
votes
1 answer

Unable to access web content's request object when linked to asset publisher

On adding a web content in an asset publisher, we are getting empty request object but if we add the same web content in web content display then we are able to see the request object. Here is what I tried: Create a web content and try to print…
ankurjhawar
  • 315
  • 1
  • 4
  • 14
0
votes
1 answer

Read a cookie value in portal_normal.vm using path attribute

I am trying to get the cookies value in portal_normal.vm of my custom liferay theme. At first I am setting a cookie value on click event using JavaScript. In some pages I able to get the cookies in theme but some pages I am not able to get the…
0
votes
1 answer

Liferay 6 - Dynamic Amount Of Child Pages w/ Navigation

I'm new to Liferay and I'm trying to figure out if it's possible to dynamically add or subtract child pages on the fly. From what I've done so far I've only been able to use the Admin Control Panel to add a static amount of child pages to a main…
Kyle Bridenstine
  • 6,055
  • 11
  • 62
  • 100
0
votes
1 answer

Print variable value inside an html string in Velocity

I need to append a suffix to an URL in Velocity (inside a Liferay template). I have the following (simplified) code: #set($isMobile = "") #set($isMobile = "-mobile")
Luca Detomi
  • 5,564
  • 7
  • 52
  • 77
0
votes
2 answers

Liferay 6 - Displaying a web content page

I'm using Liferay for the first time at my job and I'm finding it difficult to do what at first glance seemed like an easy scenario. I've just been going over countless forms and tutorials but non of them have given me the full scope or path to the…
Kyle Bridenstine
  • 6,055
  • 11
  • 62
  • 100
0
votes
2 answers

Liferay access DB table in theme: No bean named 'com.colors.themes.service.ColorLocalService' is defined

I have a theme project in liferay. I have created a new table called colors in my liferay MySQL database. The colors table is given below Actually I have a requirement that a particular css file should be loaded in theme based on the color table…
Alex Man
  • 4,746
  • 17
  • 93
  • 178
0
votes
1 answer

Liferay - get folder ID using folder name in velocity

I know how to get groupid in liferay velocity theme using: #set ($scopeGroupId = $getterUtil.getLong($group_id)) However I also need to get a folder's ID using its name. I have been researching for a while and don't seem to find a way to do that.…
0
votes
2 answers

How to access selection box field of Structure in Template using vm?

I want to create a Liferay web content which will display selection box of multiple states. I created one select field in Structure for showing States and gave multiple options such as- Punjab, Karnataka, Keral,.... Now I want to access these select…
0
votes
1 answer

Liferay retrieve specific web content from velocity template

I'm trying to retrieve other web contents / articles from inside another a velocity template. What I would like to to get is a list with published articles of the latest version with structure name 'Game'. I tried to use search but with no luck at…
0x_Anakin
  • 3,229
  • 5
  • 47
  • 86
1 2 3
8 9