Fórumok

Nyitólap » Liferay Portal » English » 2. Using Liferay » General

Kombinált nézet Egyszerű nézet Fa-nézet
Szálak [ Előző | Következő ]
toggle
Dominik domih
Velocity in .vm files vs. Velocity in Web Content
2011. augusztus 24. 6:03
Válasz

Dominik domih

Rangsorolás: Junior Member

Hozzászólások: 53

Csatlakozás dátuma: 2008. november 10.

Legújabb hozzászólások

I have a question to using velocity in liferay. There are two (or possibly more) ways to use velocity in liferay.
  1. Velocity in .vm files for the main theme layout
  2. Velocity in Web Content Templates to create Web Content forms


My need is to get the Community Name within a web content display. So I found $community_name in the theme/classic/templates/navigation.vm file. When trying to reuse the variable within a Web Content Template it will not be parsed. What am I doing wrong or is this a misunderstanding with a velocity context. Isn't it portal wide the same?

Can somebody explain me please or is there another way to display the community name within a web content display?

Thanx in advance...
Oliver Bayer
RE: Velocity in .vm files vs. Velocity in Web Content
2011. augusztus 24. 6:48
Válasz

Oliver Bayer

Rangsorolás: Liferay Master

Hozzászólások: 751

Csatlakozás dátuma: 2009. február 18.

Legújabb hozzászólások

Hi Dominik,

there are two java classes in which you define which data is accessible in vm by using a given parameter name.

  • VelocityVariables (all variables defined here are accessible in theme vm's)
  • JournalVmUtil (variables which can be used inside journal templates)


The variable "groupId" should be set inside journal templates. You should be able to use it to retrieve the group object and then output the group name.

HTH Oli
David H Nebinger
RE: Velocity in .vm files vs. Velocity in Web Content
2011. augusztus 24. 7:14
Válasz

David H Nebinger

Rangsorolás: Liferay Legend

Hozzászólások: 4496

Csatlakozás dátuma: 2006. szeptember 1.

Legújabb hozzászólások

In order to use velocity, you give it a template file and also properties (beans) to use when processing the template. So you're going to be limited in your template to the beans that are defined.

It's quite possible that although you cannot access the value directly as the theme templates can, that you might be able to get there by navigating through the beans that are available.
Dominik domih
RE: Velocity in .vm files vs. Velocity in Web Content
2012. március 16. 9:55
Válasz

Dominik domih

Rangsorolás: Junior Member

Hozzászólások: 53

Csatlakozás dátuma: 2008. november 10.

Legújabb hozzászólások

Hi Guys!

Thanks for your response. It was quite helpful to find out which options i have. In the end I simply extended the JournalVmUtil.java by
1velocityContext.put("groupName", GroupLocalServiceUtil.getGroup(groupId).getName());
to the transform method.

Now I could do
1$groupName

to get the community name in wcm with velocity emoticon

cheers
Paro Nasser
RE: Velocity in .vm files vs. Velocity in Web Content
2012. március 2. 5:20
Válasz

Paro Nasser

Rangsorolás: New Member

Hozzászólások: 15

Csatlakozás dátuma: 2012. január 12.

Legújabb hozzászólások

Hi Dominik,

can you please say what exactly you do or post your JournalVmUtil.java?
Dominik domih
RE: Velocity in .vm files vs. Velocity in Web Content
2012. március 16. 9:56
Válasz

Dominik domih

Rangsorolás: Junior Member

Hozzászólások: 53

Csatlakozás dátuma: 2008. november 10.

Legújabb hozzászólások

Look at the transform(..) - method in this file. There are already some lines starting with
1velocityContext.put("variableName", variableValue)

You can assign any name for variableName. This can be used directly in the template by
1$variableName



For example: You declare in JournalVmUtil.java
1String xy = "a string";
2//now lets forward this string to our template engine so we can use it in a Web Content Template
3velocityContext.put("myString", xy);


Deploy the bundle and create a new wcm template with
1$myString


Save the template, create a web content based on this template. The page with your wcm content will return
a string


Edit: I'm using LR 5.2.3 for this...
Paro Nasser
RE: Velocity in .vm files vs. Velocity in Web Content
2012. március 8. 2:35
Válasz

Paro Nasser

Rangsorolás: New Member

Hozzászólások: 15

Csatlakozás dátuma: 2012. január 12.

Legújabb hozzászólások

Hi Dominik,

somehow my JournalVmUtil.java look different, not how you discript. The JournalVmUtil is under portal-impl/src/com.liferay.portlet.journal.util ?

 1package com.liferay.portlet.journal.util;
 2
 3import com.liferay.portal.kernel.xml.Element;
 4import com.liferay.portlet.journal.TransformException;
 5
 6import java.util.List;
 7import java.util.Map;
 8
 9/**
10 * @author      ......
11 */
12public class JournalVmUtil {
13
14    public static List<TemplateNode> extractDynamicContents(Element parent)
15        throws TransformException {
16
17        return _instance._velocityTemplateParser.extractDynamicContents(
18            null, parent);
19    }
20
21    public static String transform(
22            Map<String, String> tokens, String viewMode, String languageId,
23            String xml, String script)
24        throws TransformException {
25
26        return _instance._velocityTemplateParser.transform(
27            null, tokens, viewMode, languageId, xml, script);
28    }
29
30    private JournalVmUtil() {
31        _velocityTemplateParser = new VelocityTemplateParser();
32    }
33
34    private static JournalVmUtil _instance = new JournalVmUtil();
35
36    private VelocityTemplateParser _velocityTemplateParser;
37
38}


there is no line with
1velocityContext.put("variableName", variableValue)


Thanks 4 help!
Bhupesh Nagda
RE: Velocity in .vm files vs. Velocity in Web Content
2012. március 16. 1:30
Válasz

Bhupesh Nagda

Rangsorolás: New Member

Hozzászólások: 4

Csatlakozás dátuma: 2012. március 16.

Legújabb hozzászólások

Hi
I am a bit new to this velocity technology, I want to add some images to the existing(classic) theme and work on the look and feel . I am able to edit the CSS through custom.css but when I add image through HTML in portal-normal.vm file image is not shown in the portal. i am adding the following code in portal-normal.vm

<img src="../images/layout/top-header.jpg" alt ="Sorry Image Not Available"/>

is there any specific folder in which I should keep the image file?? i tried various paths but its not working. Also do i need to change some code in the velocity file other than adding the <img> tag??
Dominik domih
RE: Velocity in .vm files vs. Velocity in Web Content
2012. március 16. 10:10
Válasz

Dominik domih

Rangsorolás: Junior Member

Hozzászólások: 53

Csatlakozás dátuma: 2008. november 10.

Legújabb hozzászólások

@paro: I was using 5.2.3 for this. Maybe that has changed since LR 6

@Bhupesh: I suggest to deactivate the caching so the server compiles your .vm files every time they are changed. Search the forum for more information when switching to liferay developer mode! e.g. here