Hiding an Empty Editable Text Web Part in Kentico

by Jeff Steil on April 15, 2016

Hiding an Empty Editable Text Web Part in Kentico

We just had a project where we used an Editable Text web part to allow editors to enter a quotation at the top of a page.

To apply the quote-like styling, we wrapped the editable text web part in a div.

Everything worked great when a quotation was entered, however, we had a problem when the quotation didn't have any content.  The quotation still displayed, but there wasn't anything inside!

Ultimately, what we needed to do was hide the Editable Text web part on the live site when it didn't have any content while still displaying it for editors.  After trying a few different things, I stumbled across a very elegant solution on Stack Overflow.  As the solution describes, we set the visibility of the web part (with an id of et2) using the following macro:

{% (ViewMode != "LiveSite") || (et2 != null && et2.Trim() != "") #%}

Checking the ViewMode ensures that the web part will always be visible to editors.  Our solution varies slightly from the solution I found on Stack Overflow in that we are first checking to see if the web part id exists on the page and if it does, trimming the content and not displaying the web part if it is an empty string.  I found that editors sometimes do unexpected things and in one case we had an editor deleting the content by highlighting it and then using the space bar to delete.  The end result was that the quotation looked empty but actually had a space in it.  Trimming the content helps catch that.

#editable #text #tip #webpart

Jeff Steil
Hi Jen,
Thanks for reading the article. Yes, you are correct, it should have been id and not title. Thanks for catching this, I have made the correction.
9/11/2017 5:42:45 PM

This is great thanks! Although I think you meant that the id of the editabletext was et2 rather than the title?
8/8/2017 6:20:20 AM

 Security code