Liferay, how to initiate the certain web content in Velocity

1.2k views Asked by At

I've been playing around of this issue for awhile now and can't get my head wrapped around of it. I'm using Liferay 6.1 CE GA2.

Goal:

User editable content, for example footer in each page. I've created the web content which id is 12701.

Method:

#set ($local_temp_content = $journalContentUtil.getContent($scope_group_id, "12701", null, "$locale", $theme_display))
$local_temp_content<br />

Issue: It won't return anything sensible. It's just printing "$local_temp_content" as the result.

Any pointers how to debug this issue?

2

There are 2 answers

1
Daniele Baggio On

This is a velocity macro to retrieve a web content by ID from local scope first and then by global scope:

#macro(glarticle $temp_article_id)

    #set ($temp_content = "")

    #set ($scope_group_id = $theme_display.scopeGroupId)
    #set ($global_group_id = $theme_display.companyGroupId)

    #set ($temp_content = $journalContentUtil.getContent($scope_group_id, $temp_article_id, null, "$locale", $theme_display))
    #set ($temp_content = "$!{temp_content}")

    #if ($temp_content.length() == 0)
        #set ($temp_content = $journalContentUtil.getContent($global_group_id, $temp_article_id, null, "$locale", $theme_display))
    #end

    $!{temp_content}
#end

How to use it:

#glarticle('1234')
0
Martin Gamulin On

For debugging velocity try outputting every part of your call.

scope_group_id = $scope_group_id<br>
theme_display = $theme_display<br>
journalContentUtil = $journalContentUtil<br>

If you get exactly what you wrote than that variable is not available.
If all are resolved then possibilitis are:

  • wrong article id
  • there was exception during article rendering (you should check log)