Foros de discusión
Velocity in .vm files vs. Velocity in Web Content
Dominik domih, modificado hace 12 años.
Velocity in .vm files vs. Velocity in Web Content
Junior Member Mensajes: 57 Fecha de incorporación: 10/11/08 Mensajes recientes
I have a question to using velocity in liferay. There are two (or possibly more) ways to use velocity in liferay.
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...
- Velocity in .vm files for the main theme layout
- 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, modificado hace 12 años.
RE: Velocity in .vm files vs. Velocity in Web Content
Liferay Master Mensajes: 894 Fecha de incorporación: 18/02/09 Mensajes recientes
Hi Dominik,
there are two java classes in which you define which data is accessible in vm by using a given parameter name.
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
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, modificado hace 12 años.
RE: Velocity in .vm files vs. Velocity in Web Content
Liferay Legend Mensajes: 14916 Fecha de incorporación: 2/09/06 Mensajes recientes
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.
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, modificado hace 12 años.
RE: Velocity in .vm files vs. Velocity in Web Content
Junior Member Mensajes: 57 Fecha de incorporación: 10/11/08 Mensajes recientes
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
Now I could do
to get the community name in wcm with velocity
cheers
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
velocityContext.put("groupName", GroupLocalServiceUtil.getGroup(groupId).getName());
to the transform method.Now I could do
$groupName
to get the community name in wcm with velocity
cheers
Paro Nasser, modificado hace 12 años.
RE: Velocity in .vm files vs. Velocity in Web Content
New Member Mensajes: 15 Fecha de incorporación: 12/01/12 Mensajes recientes
Hi Dominik,
can you please say what exactly you do or post your JournalVmUtil.java?
can you please say what exactly you do or post your JournalVmUtil.java?
Dominik domih, modificado hace 12 años.
RE: Velocity in .vm files vs. Velocity in Web Content
Junior Member Mensajes: 57 Fecha de incorporación: 10/11/08 Mensajes recientes
Look at the transform(..) - method in this file. There are already some lines starting with
You can assign any name for variableName. This can be used directly in the template by
For example: You declare in JournalVmUtil.java
Deploy the bundle and create a new wcm template with
Save the template, create a web content based on this template. The page with your wcm content will return
Edit: I'm using LR 5.2.3 for this...
velocityContext.put("variableName", variableValue)
You can assign any name for variableName. This can be used directly in the template by
$variableName
For example: You declare in JournalVmUtil.java
String xy = "a string";
//now lets forward this string to our template engine so we can use it in a Web Content Template
velocityContext.put("myString", xy);
Deploy the bundle and create a new wcm template with
$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, modificado hace 12 años.
RE: Velocity in .vm files vs. Velocity in Web Content
New Member Mensajes: 15 Fecha de incorporación: 12/01/12 Mensajes recientes
Hi Dominik,
somehow my JournalVmUtil.java look different, not how you discript. The JournalVmUtil is under portal-impl/src/com.liferay.portlet.journal.util ?
there is no line with
Thanks 4 help!
somehow my JournalVmUtil.java look different, not how you discript. The JournalVmUtil is under portal-impl/src/com.liferay.portlet.journal.util ?
package com.liferay.portlet.journal.util;
import com.liferay.portal.kernel.xml.Element;
import com.liferay.portlet.journal.TransformException;
import java.util.List;
import java.util.Map;
/**
* @author ......
*/
public class JournalVmUtil {
public static List<templatenode> extractDynamicContents(Element parent)
throws TransformException {
return _instance._velocityTemplateParser.extractDynamicContents(
null, parent);
}
public static String transform(
Map<string, string> tokens, String viewMode, String languageId,
String xml, String script)
throws TransformException {
return _instance._velocityTemplateParser.transform(
null, tokens, viewMode, languageId, xml, script);
}
private JournalVmUtil() {
_velocityTemplateParser = new VelocityTemplateParser();
}
private static JournalVmUtil _instance = new JournalVmUtil();
private VelocityTemplateParser _velocityTemplateParser;
}</string,></templatenode>
there is no line with
velocityContext.put("variableName", variableValue)
Thanks 4 help!
Bhupesh Nagda, modificado hace 12 años.
RE: Velocity in .vm files vs. Velocity in Web Content
New Member Mensajes: 4 Fecha de incorporación: 16/03/12 Mensajes recientes
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??
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, modificado hace 12 años.
RE: Velocity in .vm files vs. Velocity in Web Content
Junior Member Mensajes: 57 Fecha de incorporación: 10/11/08 Mensajes recientes
@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
@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