How to use the "source" parameter of the "code" macro to query a property

The
extension code macro describes the source parameter to show property values.

An attempt with something like

{{code source="object_property:XWiki.IFrameMacro.XWiki.WikiMacroClass.code" / }}

produces an irritating error message “Current user is not allowed to access document[…with the reference to the document containing the request …]”

I suppose I misunderstand the syntax.

The problem is not to get the result as I can do with calls like

{{groovy}}
"{{code}}"+xwiki.getDocument("XWiki.IFrameMacro").getObject("XWiki.WikiMacroClass").get("code")+"{{/code}}"
{{/groovy}}

or

{{velocity}}
{{code}}$xwiki.getDocument("XWiki.IFrameMacro").getObject("XWiki.WikiMacroClass").get("code"){{/code}}
{{/velocity}}

but using standard macros seems to me to be a better solution for documentation tasks.

That’s because this is not the right syntax, you might want to take a look at Model Module (XWiki.org).

Just notice that it’s the code macro documentation which was wrong, actually, fixed that.

Thanks - I inserted the ^

{{code source="object_property:XWiki.IFrameMacro^XWiki.WikiMacroClass.code" / }}

but I still get the irritating error message - now with the correct destination document. This happens with my own macros too.

My account belongs to the XWikiAdmin group (with all rights)

I just reproduced that indeed and that’s a mistake I made, fixing that right away, and it will be part of 14.10.4 which is released beginning of next week.

the problem when you do things like this (and the reason the source parameter was introduced) is that it’s very fragile: the content you insert might contain a {{/code}} string.

Yes, this problem has affected me too. (Sorry, I kept the posting simple as a proof of concept)

I solved this by inserting some invisible spaces for critical character sequences, by adding an

.replaceAll(/(?s)\{\{/,'\u200B{\u200B{')

two times (!).

But it is better to get the function by a standard macro.

While waiting for a fix of the object property source, a safer approach would be to use the script: source type as in:

{{velocity}}
#set ($codeContent = $xwiki.getDocument("XWiki.IFrameMacro").getObject("XWiki.WikiMacroClass").getValue("code"))
{{code source="script:codeContent"/}}
{{/velocity}}