| Question | How Do I Embed Xwiki Code As Text? |
| Answer |
Including XWiki code as part of your text. (Escaping Xwiki code)Sometimes, especially when we are trying to create these FAQs and documentation for Xwiki, we will need to display XWiki programming code as part of our text. For example, if we are trying to write a tutorial on how to create a Blog in XWiki. If you simply put the code inside the standard {code} tags, the rendering engine will still execute it. The reason is that the special characters "#" and "$" must be escaped. When the rendering engine sees that this character is escaped, it ignores it as a processing instruction and then just displays it. The escape character for Xwiki code is the backslash "\" character. So, to include a code section, type it in like this:\{code\}
\\#set(\$page = \$doc.fullName)
\\#includeForm("Test.BlogMacro")
\{code\}\#set(\$page = \$doc.fullName)
\#includeForm("Test.BlogMacro")\{code\}
\{pre\}
\#set(\$code = \$xwiki.getDocument("Doc.BlogMacro").content)
\#set(\$code = \$code.replace("\#","\\\#"))
\#set(\$code = \$code.replace("\$","\\\$"))
\$code
\{/pre\}
\{code\}#set($code = $xwiki.getDocument("Doc.BlogMacro").content) #set($code = $code.replace("#","\\#")) #set($code = $code.replace("$","\\$")) $code |
Version 1.8 last modified by Vincent Massol on 14/06/2007 at 09:31
Document data
Attachments:
No attachments for this document
Comments: 0