问题
Is that it is possible embed web content in a template velocity? I have two web contents and I want to unite the two into a single one.
I tried this:
#set ($webcontent-id = "13054")
#set ($webcontent=$journalContentUtil.getContent($group_id, $webcontent-id,null,"$locale",$theme_display))
<div> $webcontent </div>
#set ($webcontent-id = "13065")
#set ($webcontent=$journalContentUtil.getContent($group_id, $webcontent-id,null,"$locale",$theme_display))
<div> $webcontent </div>
However, it displays the variable. I think I did not access the service in a webcontent.
回答1:
Web content templates do not have access to the ThemeDisplay directly. They can access request information via the $request map, which contains among other things variables from ThemeDisplay. This wiki page lists the variables that can be used from templates.
Also, when calling Liferay services from velocity templates you need to make sure that all arguments have the correct type. You can use $getterUtil to accomplish this, for example to convert a String to Long.
Here's a revised version of your example:
#set ($group_id = $getterUtil.getLong($request.theme-display.scope-group-id))
#set ($webcontent-id = "58007")
#set ($webcontent=$journalContentUtil.getContent($group_id, $webcontent-id, "", "$locale", ""))
$webcontent
来源:https://stackoverflow.com/questions/15390704/how-to-embed-webcontent-in-liferay