First of all, I'm a very newbie with Liferay.
It's been some days I'm scratching my head with this, but can't find anything for that, even if it seems easy at first look.
I'm creating a portlet with its own preferences for Liferay 6.2, and one of these preferences is required to be set in the <head> tag of the HTML generated by my FreeTemplate theme.
The most logic approach I was thinking of, is to create a variable from my portlet, so that it can be displayed in my theme, but I couldn't find any way to achieve this.
My current portlet's code:
HttpServletRequest request = PortalUtil.getHttpServletRequest(portletRequest);
Map<String, Object> var = new HashMap<>();
var.put("test", "Hello World");
request.setAttribute(WebKeys.VM_VARIABLES, var);
My theme code:
<#if test??>
true: ${test}
<#else>
false
</#if>
I keep getting false.
Is my approach wrong? If yes, what should I do? If it's not, how could I do that?
Note: I'm aware about FreeTemplate's <h:head>, but surprisingly, using it provokes the template to generate a second <head> tag in my <body>, which is, you'll agree, absolutely unacceptable. Maybe I'm not using it correctly?
Edit
To give more about my context, I'm currently working on a social sharing portlet that must allow 1) to share the current page and 2) to configure how the link will appear on Facebook/Twitter (using OpenGraph <meta /> tags). My first attempt was to put this configuration to the theme, but my customer absolutely wants it to be in the portlet.
#set ($VOID = $velocityPortletPreferences.setValue('display-style', '1')) #set ($VOID = $velocityPortletPreferences.setValue('portletSetupShowBorders', 'false')) $theme.runtime("yourdeployable_WAR_youportlet", '', $velocityPortletPreferences.toString()) #set ($VOID = $velocityPortletPreferences.reset())- You will also find further info when search for "Liferay theme embed custom portlet" (sorry was not able to format comments) - Andre AlbertvelocityPortletPreferences? When I try to use it in my template, I get an InvalidReferenceException - DeuchnordWebKeys.VM_VARIABLESi wrongly thought your are using Velocity-Markup. In your case there should be afreeMarkerPortletPreferencesvariable instead. It is used to embed your portlet without any portlet borders. Also note that "yourdeployable_WAR_youportlet" will be your Portlet ID - Andre Albert