cogRemove an Object from a document
TypeSnippet
Category
Developed by

Philipp Roessler

Rating
0 Votes
LicenseGNU 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 an 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}}
     

Get Connected