This project is read-only.

Prevent widget display based on current content item

Topics: Customizing Orchard
Jan 9, 2014 at 5:56 PM
Is there a way to prevent a widget from being rendered based on a content part in the widget? Would this need to be done in a result filter? If so, how can I make sure that it gets called after the default widget result filter?
Jan 9, 2014 at 7:36 PM
Conditionally not returning the widget shape from the driver might work.

Jan 9, 2014 at 7:38 PM
I already tried that. Returning a null from the driver still renders the widget, just without any content.
Jan 9, 2014 at 7:42 PM
Can you post the code piece you return null?

Jan 9, 2014 at 7:50 PM
Ignore that, sorry, I confused local zone placement and global zones.

Jan 13, 2014 at 3:19 PM
I'll give another try.

The only mechanism I know of in Orchard to render or not a widget is layers. What might work is to
create a custom layer rule that checks for the condition, something similar to contenttype layer rule. Even if this works, the layers would command multiple widgets, so you can prevent all widgets assigned to the layer but cannot single out one of them.

Alternatively, you can try removing the widget shape from the zone:

I think you can try it in Layout template, which checks if there are any shapes in the zones before rendering divs around them. So before checking, traversing the shape tree and removing widget shapes (and setting zones to null if no more widgets left for the zone) might work.