Projection Widget: Hide if Empty

Topics: Writing themes
Sep 16, 2012 at 5:26 PM
Edited Sep 16, 2012 at 5:26 PM

I have a projection widget for a query, and I render it with a custom template.  I'd like to hide the entire widget if there aren't any items returned by the projection query.  What's the most proper way to do this?

For background, I've tried to use shape tracing to examine the model being passed to the projection widget and look for a property that has the actual items, but that doesn't seem to exist.  I have a suspicion that I should be using a placement.xml -- but I don't really understand how that works.

Thanks for any help!


Sep 16, 2012 at 7:05 PM

Placement won't help with that, no. When used with a layout in properties mode, there is an option to output some specific text when the query returns empty. If in content mode like you seem to be, you probably need to build an alternate template for the list shape that takes that into account.

Sep 21, 2012 at 8:17 PM

I was using the alt template for the widget, as it seems you can be more specific with naming.  Specifically, I can create an alternative template for the widgets technical name (Widget-Name-[technical_name].cshtml) where the list template alternatives seem to be far more generic (I'm using shape tracing) and either I have to override the list template by ID (what if I delete the widget, then create a new one -- now the template ID changed?) or override all list rendering, at least on a specific layer.

So my hope was that in the widget template I could check if the projection returned any items, and if it did, then render the widget, else render nothing.

Again, I'm really new to this, and I feel like I'm probably approaching this in a harder than necessary fashion.  Thanks for taking the time to respond previously -- I appreciate the help!

Sep 21, 2012 at 8:28 PM

Ok then, i's probably the list template shape that you need to alternate, more than the widget template, which is just going to be a container for local zones.