Remove Shape/Zone/Widget - is it possible?

Topics: Customizing Orchard, Troubleshooting, Writing themes
May 8, 2012 at 1:51 PM
Edited May 8, 2012 at 1:52 PM

I know I can do something like:

WorkContext.Layout.Footer
    .Add(New.Whatever(), "5");

to add something.  Is there a similar mechanism to remove something?

Say I have a widget in teh Footer named "Whatever" and I wanted to remove it in a particular instance?

Thanks.

Developer
May 8, 2012 at 3:12 PM

I'm not entirely sure but It think this is possible. That Add() method is a dynamic Clay behaviour, there is really no such method on the Footer itself, however there is a list in the shape containing all the child items. Inspect the Footer shape with the debugger, you should see a collection inside it (it's maybe even called Items), perhaps you can call Remove() on that.

May 8, 2012 at 4:19 PM
Edited May 8, 2012 at 4:19 PM

Was trying Remove() last night and getting errors that it wasn't part of Clay, but then again I was trying to enter different parameters to get a specific widget in a zone out (with an ID). Otherwise if I just leave it as "Remove()" it doesn't work.

Any ideas on how to do that in terms of code example. I am imagining

WorkContext.Layout.WhateverZoneIHave.Remove([What goes in here - if anything?]);

Thanks for your efforts.

Developer
May 8, 2012 at 4:23 PM
Edited May 8, 2012 at 4:24 PM

As I've said there is an underlying collection, that's where you perhaps can remove from. Have you tried to find it with the debugger as I advised?

Coordinator
May 8, 2012 at 5:00 PM

You need to have a reference to the object you're removing (so find it first) to pass as a parameter to Remove. There is also a RemoveAt method that takes an int.

May 8, 2012 at 5:22 PM

@Piedone, Yes I used the debugger. I got the ID of 134 for the widget, its just the actual code that I cannot get right.

@bertrandleroy Thanks for the RemoveAt suggestion, I am going to try that.