Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Path Finder LifeRay
working with VM variables?
December 1, 2012 2:07 AM
Answer

Path Finder LifeRay

Rank: Expert

Posts: 262

Join Date: September 18, 2009

Recent Posts

Hi All,

I'd like to know how to work with the velocity variables?
While trying to work with themes i have seen the templates folder, and i came to know that vm files was written in velocity mark up language.

Now my question are:

where these variables are defined, for example($nav_item,$nav_item.getURL())etc.,not specifically about nav, variables like these in the whole vm files.

how to get these variables?if i need to define new variables where i can set?

is there any documentation/tutorial available for creating the vm files?please guide me

regards
path
James Falkner
RE: working with VM variables?
December 1, 2012 3:14 AM
Answer

James Falkner

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1325

Join Date: September 17, 2010

Recent Posts

Path Finder LifeRay:
Hi All,

I'd like to know how to work with the velocity variables?
While trying to work with themes i have seen the templates folder, and i came to know that vm files was written in velocity mark up language.

Now my question are:

where these variables are defined, for example($nav_item,$nav_item.getURL())etc.,not specifically about nav, variables like these in the whole vm files.

how to get these variables?if i need to define new variables where i can set?

is there any documentation/tutorial available for creating the vm files?please guide me

regards
path


Variables are already available to your template files. See this wiki page for details.
Atif Hussain
RE: working with VM variables?
December 1, 2012 10:16 AM
Answer

Atif Hussain

Rank: Junior Member

Posts: 47

Join Date: April 3, 2012

Recent Posts

One way of setting defining and using custom VM variables is:

Step 1:

Make a variable " show-control-panel " of boolean type

 1
 2import com.liferay.portal.kernel.events.Action;
 3import com.liferay.portal.kernel.events.ActionException;
 4import com.liferay.portal.kernel.util.WebKeys;
 5import com.liferay.portal.model.User;
 6
 7public class CustomAction extends Action
 8{
 9    static Logger logger = Logger.getLogger(CustomAction.class);
10   
11    @Override
12    public void run(HttpServletRequest request, HttpServletResponse response)
13            throws ActionException {
14       
15       
16        Map<String, Object> vmVariables = new HashMap<String, Object>();
17       
18        HttpSession session    =    request.getSession(true);
19       
20        if(session!=null)
21        {
22            User user    =    (User)    session.getAttribute("USER");
23            
24            if(user !=null && user.getJobTitle().equalsIgnoreCase("admin"))
25            {
26                vmVariables.put("show-control-panel", true);
27            }
28            else
29            {
30                vmVariables.put("show-control-panel", false);
31            }
32            request.setAttribute(WebKeys.VM_VARIABLES, vmVariables);
33        }
34    }
35}


Step 2:

now in theme you can access this variable with " $show-control-panel "
Gouse Basha
RE: working with VM variables?
December 3, 2012 1:48 AM
Answer

Gouse Basha

Rank: New Member

Posts: 10

Join Date: November 30, 2012

Recent Posts

Path Finder LifeRay:
Hi All,

I'd like to know how to work with the velocity variables?
While trying to work with themes i have seen the templates folder, and i came to know that vm files was written in velocity mark up language.

Now my question are:

where these variables are defined, for example($nav_item,$nav_item.getURL())etc.,not specifically about nav, variables like these in the whole vm files.

how to get these variables?if i need to define new variables where i can set?

is there any documentation/tutorial available for creating the vm files?please guide me

regards
path


You can set your variables in init_custom.vm file.
Anil Sunkari
RE: working with VM variables?
December 3, 2012 3:24 AM
Answer

Anil Sunkari

Rank: Expert

Posts: 412

Join Date: August 11, 2009

Recent Posts

For Reference : Just have a look at VelocityVariables.java in portal source!!
Anil Sunkari
RE: working with VM variables?
December 11, 2012 9:44 PM
Answer

Anil Sunkari

Rank: Expert

Posts: 412

Join Date: August 11, 2009

Recent Posts

You can get it from portal source.Downlod it from the site (or) sourceforge.net
Luis Mas
RE: working with VM variables?
December 11, 2012 8:14 AM
Answer

Luis Mas

Rank: Regular Member

Posts: 146

Join Date: May 18, 2009

Recent Posts

Or in http://docs.liferay.com/portal/6.1/