Remove Object From Page
Last modified by Sergei Kulagin on 2022/12/21 14:09
Remove an Object from a document |
Type | Snippet |
Category | |
Developed by | Philipp Roessler |
Rating | |
License | GNU Lesser General Public License 2.1 |
Table of contents
Description
The following code outlines how you would programatically remove an object from a page (document). We use it to build a URL (i.e. HTTP request) which specifies the object type and a field value to distinguish the object.
{{velocity}}
## Usage example:
## http://localhost:8080/xwiki/bin/view/Support/qwer?removeobject=XWiki.XWikiComments&removeobjectfield=comment&removeobjectvalue=ccc1
## removes the (first) object of type 'XWiki.XWikiComments' whose 'comment' property is set to 'ccc1' from the document 'Support/qwer'.
#if($context.action=='view' && $request.removeobject!='' && $request.removeobjectfield!='' && $request.removeobjectvalue!='')
## Remove object from document
#set($obj0=$doc.getObject($request.removeobject,$request.removeobjectfield,$request.removeobjectvalue))
#if($obj0)
#if($doc.removeObject($obj0))
## Save the changed document with a comment
$doc.save("Removed object ${request.removeobject} (${request.removeobjectfield}=${request.removeobjectvalue})")
#end
#end
#end
{{/velocity}}
## Usage example:
## http://localhost:8080/xwiki/bin/view/Support/qwer?removeobject=XWiki.XWikiComments&removeobjectfield=comment&removeobjectvalue=ccc1
## removes the (first) object of type 'XWiki.XWikiComments' whose 'comment' property is set to 'ccc1' from the document 'Support/qwer'.
#if($context.action=='view' && $request.removeobject!='' && $request.removeobjectfield!='' && $request.removeobjectvalue!='')
## Remove object from document
#set($obj0=$doc.getObject($request.removeobject,$request.removeobjectfield,$request.removeobjectvalue))
#if($obj0)
#if($doc.removeObject($obj0))
## Save the changed document with a comment
$doc.save("Removed object ${request.removeobject} (${request.removeobjectfield}=${request.removeobjectvalue})")
#end
#end
#end
{{/velocity}}