{{velocity}}
#macro(getLastComment $itemdoc)
#set($maxLen=120)
#set($class="XWiki.XWikiComments")
#set($name=$itemdoc.fullName)
#set($xwlquery="select obj.comment from Document doc, doc.object($class) as obj where doc.fullName='$itemdoc.fullName' order by obj.date desc")
#set($list=$services.query.xwql($xwlquery).setLimit(1).execute())
#if($list.size()>0)
#set($str=$list.get(0))
#set($len=$str.length())
#if($len>$maxLen)
#set($str=$str.substring(0,$maxLen)+"...")
#end
#set($rez=$str)
#else
#set($rez="")
#end
$rez
#end
{{/velocity}}
This is a simple macro for getting last comment from a page. Problem, that I get as result:
“#getLastComment($doc)” - but not a real comment. If I write macro text inside custom display directly - all is ok. What solution can be for this situation?
The Velocity code (getLastComment) is evaluated before the wiki syntax (the include macro). Move the include outside of the Velocity macro as suggested by @vmassol .
Firstly I tried to check macro - all is ok.
If write #getLastComment($doc) directly on a page with macro - I gtet result - last comment.
As I understand, problem doesn’t linked with “custom display” of a property. I wrote as you and Vincent written:
same result - problem exists. Also I tried directly on a different page (inside Sandbox.TestPage3) - same result - problem exists.
PS. I am using XWiki 8.4.4