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

Dynamically change language in liferay

Following is my requirement: I need to change language dynamically. So I have one button which will have toggle values. So when value is "English" it will show content in english and when value is something else say "Hindi" then it will show content…
suyash
  • 1,254
  • 1
  • 15
  • 33
0
votes
1 answer

Fetching child elements of parent using velocity code

I am keeping Asia as a parent element. Under that, I am keeping India and China as child elements. I want to fetch both of the countries by using velocity code. Below is my code: I am using the method getChildren() and I am getting only the first…
user3853393
  • 233
  • 4
  • 25
0
votes
0 answers

Extend ServicePreAction class and add attribute under the key WebKeys.VM_VARIABLES

I need to add some custom velocity variables in liferay 6.0.6 running on tomcat 6. Please tell me a way to do it. I read it in a blog that we need to extend ServicePreAction class and add attribute under the key WebKeys.VM_VARIABLES. But I am not…
aayushdriger
  • 382
  • 3
  • 19
0
votes
2 answers

How to create liferay Service xml for multiple foreign key of same primary key?

I know the question might be confusing,any ways I will explain it. Basically I have two tables. Student and Course where studentid and courseid are their corresponding primary keys. In the Student table I have two attributes courseid and…
playmaker420
  • 1,527
  • 4
  • 27
  • 52
0
votes
1 answer

Unable to create popup in liferay

I am trying to create a popup using aui script tag and i don't no why its not working please have a look at the code function popup(url){ AUI().use('aui-dialog', function(A){ var dialog = new A.Dialog({ title: 'Book…
0
votes
1 answer

How to display User name as a page title

from last few days i am trying to do some modification in SEO level, as i am working on a social portal. when i goes thru any users profile. the page title comes on window tab is "Profile|XYZ.com" If i went thru a user "TestUser"'s profile,it…
Akash
  • 816
  • 3
  • 13
  • 38
0
votes
4 answers

Unable to redirect to other page in liferay

I am trying to redirect to other page using java code and don't no why its not getting redirected. the below is the following code ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY); PortletConfig…
0
votes
1 answer

Unable to retrieve the value from DB using Liferay Service Builder

I am learning Liferay and have been stuck in a place where I don't know what to do. I will just brief out what I am doing. Creating a Library Management System using service builder and have the following Code in Service.xml file.
0
votes
1 answer

Import external resource with Freemarker or Velocity in Liferay

I want to import an external resource from the filesystem to a Webcontent Template in Liferay (6.1). Can this be done with an include instruction (#include) from Freemarker or Velocity ?
0
votes
3 answers

Liferay: How to add cookie from portlet from doEdit(RenderRequest req,RenderResponse res)

I am trying to set a cookie from portlet doEdit method like the following : Public void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException { Cookie cookie = new Cookie("url","mkyong dot com"); …
Naresh Kallamadi
  • 163
  • 1
  • 14
0
votes
1 answer

how to display data from web service in web content portlet in Liferay 6.2?

I have to display html content in web content display portlet which will be coming from web service response in Liferay 6.2. I have created wsdl jar as we always do for accessing the web service in custom portlets. But i am not sure how to access…
user2574980
  • 229
  • 1
  • 6
  • 16
0
votes
1 answer

How to call web service method from Web content display in Liferay 6.2?

I am creating a page using Liferay 6.2 where i need to display html contents sent as response from web service method. After seeing the customization and features available in web content display, i am planning to use them. As i am new to VM and…
user2574980
  • 229
  • 1
  • 6
  • 16
0
votes
1 answer

JavaScript Error because of rendered velocity line-break

I use JavaScript-code in a velocity-template and it's not working! I read content with this template and want to set this to a js-variable, but there are line-breaks in the content and I get the following error: SyntaxError: unterminated string…
0
votes
1 answer

Liferay Custom Welcome Page

I have requirement such that, to configure the welcome page of User’s Private Page with my custom portlets dynamically. On successful login User lands to his private page. Based on his roles he should see the portlets on the auto created welcome…
Rahul Dev
  • 387
  • 1
  • 4
  • 12
0
votes
3 answers

liferay dynamic datalist getfieldvalue for radio and select fields contains cruft

How do I remove the extra [" "] when retrieving DynamicDataList data from LifeRay 6.1.30 using DDLRecordLocalService getFieldValue in a velocity template for radio or select fields. Here is my VM: #set ($ddlRecordsUtil =…
john nowlin
  • 135
  • 10
1 2 3
8
9