2
votes

As of now, Liferay provides a set of global variables as defined in init.vm that can be used by theme templates. These variables are set in init.vm and is located inside Liferay ROOT.war : $PATH_TO_WEBAPPS/ROOT/html/themes/_unstyled/templates.

And Inside my custom theme portal_normal.vm, I could use it by simply adding #parse ($init). Which works great.

Now moving into my problem. I am using velocity template for sending my email address.So, Inside my portlet i have created an email template in the location as $SOME_PORTLET_NAME/src/main/webapps/template/email.vm. I could send the custom variables to the template using,

VelocityContext velocityContext = new VelocityContext();
velocityContext.put("vp", velocityParameters);

But I couldn't use the default variables provided by the Liferay as used in theme.

I am trying to use $languageUtil.get for internationalization in my email template.

What have i tried?

  • Cloning init.vm inside the template and importing it. Which didn't worked; stupid me.
  • Provide full path to the ROOT.war location of init.vm. It didn't worked either.(I am surprised it should have worked.)

Question :

  • Is there a way to use those velocity global variables in custom portlets(i.e outside theme)?

  • Could this be achievable using Java?

  • Or is it better to perform LanguageUtil.get and send the value only to template(This would be my last option)?

Thanks!!

1

1 Answers

2
votes

It might not be the full answer but a pointer where to start: You're creating a blank VelocityContext. This is naturally empty - no surprise there.

When Liferay executes its init.vm and other templates, it doesn't run on a blank context (though init.vm seems very basic). Depending on your version of Liferay, look up VelocityVariablesImpl or TemplateContextHelper for the initialization of a scripting context.

Note that this all lives in portal-impl, thus in Liferay's implementation which you typically don't have access to. You might need to duplicate the parts of the code that you're interested in as you typically can't call them directly. But then, you probably don't need the full initialization as well.

If this helps you find an actual solution, please post some hints on what you actually settled with (or a link to it)