We have several sites hosted on a Liferay 5.2 instance, consisting of multiple communities, themes, and layout templates, all working as expected. However, this setup is no longer working in the EE service packs of 5.2 (specifically, the latest EE SP5 - same as 5.2.9) or the latest 6.0.6 (CE). (Additional testing showed that this was last working in EE SP3 / 5.2.7, but became an issue in EE SP4 / 5.2.8.) We urgently need to upgrade to the latest 5.2 service pack (EE SP5) to address other issues - but upgrading to Liferay 6 is also a possible option, as long as we can find a combination of a solution and version that works.
In particular, we have files in the theme (e.g. inc-side.vm
) that are included as part of the theme, and included by the layout templates. This allows for content to be "owned" by the theme, but used in context of the various layout templates - even though the same layout templates are used across multiple sites (communities / themes). Placing this content directly in the theme (without involving the layout template) is not an option, as it needs to be placed within the UI space of the layout, and various layouts may require this content to be located in different spaces in respect to the theme.
An additional requirement is that this included content must consist of "embedded" portlets - I.E., is not drag-and-dropped into the UI per-page, but is associated with each theme / layout. By simply applying the theme + layout to a site / page, the correct portlets are automatically included on each page. This is necessary as with some of the sites / communities consisting of around 100 or more pages, adding this content per-page and keeping it consistent without being embedded in the theme + layout would not be practical nor maintainable. (Consider just 10 themes (communities) * 10 layout templates * 10 pages / community = 1,000 combinations to configure and maintain.)
Again, this was all working under 5.2.3 (including 5.2 EE SP1, SP2, and SP3) - but stopped working as of 5.2 EE SP4. We are a Liferay enterprise support customer, and have had a support ticket open for almost 2 months with no resolution on this yet provided. Nothing was mentioned concerning this in the release notes, and we have not yet been able to obtain any guidance from Liferay as to why this changed, or any successful work-arounds.
Here are some specifics for the current issue:
Easily and consistently reproducible under any new installation of 5.2 EE SP4 or SP5.
Include inc-side.vm
under the templates
directory in the theme. There is nothing special about the theme - even using a copy of Liferay's default "classic" theme will work.
In inc-side.vm
, include the following:
<p>Before Diagnostics</p>
$theme.runtime("27_INSTANCE_0000", "", $velocityPortletPreferences.toString())
$velocityPortletPreferences.reset()
<p>After Diagnostics</p>
Note that "27" is a default Liferay-provided portlet, used for simplicity, and to demonstrate that this issue is not particular to any custom-developed portlet. However, I've also created my own "diagnostics portlet" from scratch that demonstrates exactly the same issue.
In the layout template (*.tpl), include the following lines:
#set ($contextName = $themeDisplay.getTheme().getContextPath())
#set ($themeContext = $request.getAttribute("CTX").getContext($contextName))
#evaluate ($theme.include($themeContext, "/templates/inc-side.vm"))
This follows the same approach shown at http://www.liferay.com/community/forums/-/message_boards/message/772138 .
Per a suggestion from our support ticket, I also tried the following 1-line alternative to the above lines:
#parse ("$fullTemplatesPath/inc-side.vm")
(Note $fullTemplatesPath
vs. $full_templates_path
. The reason for this is that init.vm
calls #set ($full_templates_path = $fullTemplatesPath)
- but init.vm
is not included in the templates, only the theme.)
The results for either approach are identical. Any static text / HTML contained within inc-side.vm
are displayed as expected. Any Velocity directives are parsed and processed, and not displayed in the output. Logging within the portlet shows that it has executed, and even retrieves any portlet preferences that were set to velocityPortletPreferences
. The root problem is that any content generated by the portlet is not being rendered to the HTTP response. In fact, as viewed by Firefox's "View/Source" or cURL, the response contains exactly:
<p>Before Diagnostics</p>
<p>After Diagnostics</p>
In my custom portlet, I even tried calling every flush()
and close()
method I could find on the response, thinking it was a flushing-related issue.
Testing under Liferay 6.0.6 instead (assuming maybe this was only a 5.2-series issue) gives yet different but interesting results. The included *.vm file is successfully read into the page. However, it is not being evaluated as Velocity code. Unlike in 5.2 SP5 where the included VM is being executed but just not rendering, 6.0.6 is rendering but not evaluating (or executing).
We have reviewed http://www.liferay.com/web/raymond.auge/blog/-/blogs/11180056 ("Embedding portlets in themes on Liferay"), and the above approach is really "method one". "Method two" is not an acceptable option, as the use of an <iframe>
causes issues with the DOM of the page (specifically with JavaScript IPC) - and this would also require the UI size of each portlet to be known in-advance, which isn't practical or acceptable.
We are hoping that someone more familiar with Liferay and/or the Apache Velocity templating engine (used by Liferay) can provide a resolution or other acceptable work-around to this issue. I will provide any additional details or clarifications that I can.
Thanks!