0
votes

When I remove a component in Sitecore from the Experience Editor, it is removed from the page but in Content Editor the component and its datasource still here! Does anyone have a solution for this? Thank you.

1

1 Answers

0
votes

This is a bit of a tricky one as the datasource might still be referenced by other pages, or potentially by the same page in another version or language.

You could use an event handler implementation to scan the renderings on save and look for renderings that are removed (i.e. were in the original, but not the new version being saved). Then, for each one, check if they are referenced anywhere.

A sample implementation is shown in this blog: http://r-coding-sitecoreblog.blogspot.com/2013/10/cleaning-up-datasource-items.html

The other thing to consider is that your datasource might have presentation itself and may have other datasources it references. So, be sure to consider this scenario when cascading your delete from the Experience Editor.