This macro isn't bundled with any XWiki product by default.
Macro developed by the XWiki Development Team.
This macro cannot currently be downloaded separately.

Snippet Macro

Extracts a portion of code delimited by a token. This macro mimicks the behavior of the Confluence Snippet macro.

Usage

#snippet(lang, id, url)

Parameters definition

NameOptionalAllowed valuesDefault valueDescription
langnoStringnoneLanguage to be used when wrapping the content in the {code} macro
idnoStringnoneThe token id. Tokens are of the form // START SNIPPET: <id> / // END SNIPPET: <id>
urlnoStringnoneThe URL from where to get the content to display

Example

#snippet("java", "boy", "http://svn.codehaus.org/picocontainer/java/1.x/picocontainer/trunk/container/src/test/org/picocontainer/doc/tutorial/simple/Boy.java")

Result

result.png

Installation

This a Velocity macro. Since it's not bundled by default you'll have to copy/paste the following code to use it:

#macro(snippet $lang $id $url)
#set($codestart = "{CODE:$lang}")
$codestart.toLowerCase()
#set ($text = $xwiki.getURLContent($url))
#set ($delimiter = "// START SNIPPET: $id")
#set ($pos1 = $xwiki.add($text.indexOf($delimiter), $delimiter.length()))
#set ($pos2 = $text.indexOf("// END SNIPPET: $id"))
$text.substring($pos1, $pos2)
#set($codeend = "{CODE}")
$codeend.toLowerCase()
#end
Version 3.1 last modified by VincentMassol on 19/06/2008 at 22:12

Comments 0

No comments for this document

Attachments 1

Image
result.png 1.1
PostedBy: VincentMassol on 21/01/2008 (7kb )

Creator: VincentMassol on 2008/01/21 17:30
This wiki is licensed under a Creative Commons license
1.4.1.10194