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

Liferay Language switch issue

I am trying to implement multiple language support in my liferay Project. For this i added below code in portal_normal.vmfile of theme. #set( $availLanguage = $stringUtil.split("hi_IN,en_US")) $taglibLiferay.language("fm", null,…
1
vote
0 answers

Create Object in Liferay Web Content Template

I am trying to instantiate MimeMessage class using Liferay WebContent Velocity template and having difficulty with it. Here is my code #set ($properties = $portal.getClass().forName("java.util.Properties").newInstance()) #set ($VOID =…
Sri
  • 309
  • 1
  • 9
  • 24
1
vote
2 answers

css not getting applied for velocity template in Liferay Theme

I am using LIferay Theme to create a theme for a website. IN the portal_normal.vm file, I have included all the html code and css I have defined in custom.css THe problem is that css from custom.css is not getting applied to portal_normal.vm…
user2822187
  • 307
  • 2
  • 11
  • 26
1
vote
1 answer

How to hide a navigation bar in liferay theme based on the custom service response?

I am working on lIferay 6.2 portal developement where I have requirement where i have to hide a navigation bar in liferay theme based on the response from custom service. and let me know is it possible to make only one web service call for checking…
user2574980
  • 229
  • 1
  • 6
  • 16
1
vote
1 answer

How to get plid of specific portlet In Liferay velocity template

I am developing MVC Portlet and want to open specific page of my portlet through menu link via Controller. In velocity template I have portlet name of my portlet. How can i get plid of that portlet? My code is as below: #if…
1
vote
0 answers

Can Velocity or Freemarker template be used for VIEW of Custom plugin portlet?

I am trying to have a custom plugin portlet in liferay for which I can customize the view page with velocity or free-marker template like we have for Asset Publisher in Liferay 6.2. Requirement I have a screen for admin (CRUD) through which data…
Prakash K
  • 11,669
  • 6
  • 51
  • 109
1
vote
1 answer

how to use jquery rounded plugin in liferay theme?

I have developed a theme in liferay 6.1. In css I have written border-radius property, which is not working in IE6-to-IE8. border-radius is a css3 property which will work on IE9+ I want to use jquery rounded corners in my theme in order to…
ASR
  • 3,289
  • 3
  • 37
  • 65
1
vote
1 answer

Check sigin page is opened or not in liferay

I want to make some changes on template(portlet.vm) in liferay based on some condition. And condition is to know whether user is signed in or not. Something like: #if ($is_signed_in)
Sonal S.
  • 1,444
  • 1
  • 15
  • 31
1
vote
1 answer

User's Job Title in Liferay Theme

I'm trying to include the value of the user field "Job Title" in a Liferay-Theme (6.1.20), but I can't find the proper VM-variable. If there isn't one, how would I go about displaying that information or (alternatively) a custom field for users.
icke
  • 1,568
  • 1
  • 19
  • 31
1
vote
1 answer

Liferay : how to use PDF viewer from web content

I want to add link to PDF file in web content. and If i click on that PDF image link it will open up pop up same as document and media. How to achieve this ? Thanks
Hiral
  • 195
  • 1
  • 13
1
vote
2 answers

Liferay 6.1 get themeDisplay in velocity (vm) file

I'm trying to get the profile picture of my users and display it in my liferay theme. So far I've been able to access the User object trough the velocity $user variable. The user model has a method called getPortraitUrl() which takes ThemeDisplay as…
mduck
  • 197
  • 1
  • 6
  • 23
1
vote
2 answers

How to get active theme name in velocity template in Liferay

We use one theme for our desktop web page and another for responsive/mobile version of the site. But for mobile we don't always want to show images and it would be good if we can restrict it from the template, not just hiding it with CSS (because it…
Algeron
  • 269
  • 1
  • 5
  • 16
1
vote
1 answer

Find inherited user roles, assigned by a group in a Liferay Theme 6.1.1 GA2

we want to check in a Liferay-Theme for 6.1.1 GA2, if the currently signed in user has a role e.g. "myRole". The role is defined and assigned to the user, by adding the user to a group where this role is assigned. When i check the user roles in…
kidata
  • 165
  • 1
  • 2
  • 15
1
vote
2 answers

Expose String to Velocity Theme in Liferay for Social Media Tags (Open Graph)

I would like to expose some Strings to the a velocity theme in the liferay framework in order to write some HTTP headers used for social network sharing. What is important is that my Controller has to put these Strings to the velocity theme during…
cachiama
  • 590
  • 3
  • 19
1
vote
2 answers

Is there any way we can display web-content on public page randomly on page refresh?

We are using liferay 6.1 On Public page we want to display web-content in one portlet, but it should not be only selected one. we want to display it randomly on page refresh. Like on page refresh it should display different web content from group…
Hiral
  • 195
  • 1
  • 13
1 2 3
8 9