Zone gets rendered when placing an empty field in it

Topics: General
Nov 1, 2012 at 3:16 PM

1. In my Layout.cshtml I got the following code:

 @if (Model.Featured != null) {
            <section id="promo" class="section alt">
                <div class="container">

2. In my I got the following placement

    <Place Fields_Common_Text-MyField="/Featured:2" />

So basically I configure the custom field "MyField" to render in the "Featured" zone .

If I have a page where I do not provide any value for "MyField" the "Featured" zone gets rendered anyway. I assume this happens because the value of MyField is an empty string rather than null...

Is there any way to avoid this behaviour? What I would like is to keep the placement definition like stated, however, when I do not provide a value for MyField the Featured zone should not be rendered.

is there a way to add perhaps additional checks?

PS: working in webmatrix here

Nov 1, 2012 at 8:16 PM

One way you could solve this is to write a shape table provider that describes the Fields_Common_Text shape. In the OnDisplaying event, check for the value of the field. If it's null or empty, add the shape to a non-existing zone so it won't be rendered.

Nov 2, 2012 at 4:31 PM

I must apologise, but that's a bridge to far for my knowledge.

I was hoping I could get away with a fix that I could implement using WebMatrix... 


Nov 2, 2012 at 5:24 PM
Edited Nov 2, 2012 at 5:24 PM

FYI; found a solution in the meanwhile, although it is a patch rather than solving the root cause

I wrote a jquery function to find myself empty zones, or more exactly in the case described above, the zone gets rendered with 2 line feeds in it. So, this script finds the zone and removes the closest section above it. 

function cleanEmptyFeaturedZone() {
    var featuredZone = $("");
    if (!/\S/.test(featuredZone.text())) {
Nov 2, 2012 at 5:42 PM

You could also render the Zone like that:

var zoneContent = Zone(Model.Featured);

Then check if the content is empty or full of space and render it:

@if(!String.IsNullOrEmptyWhiteSpace(zoneContent)) {