Blog

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 a title of et2) using the following macro:

{% (ViewMode != "LiveSite") || (et2 != null && et2.Trim() != "") |(user)joel.dahlin|(hash)cd7417911fdab4fb816ddccbcb815a0f2dd3843ec276c3734e1784a82cc01caf%}
 

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

Comments
Blog post currently doesn't have any comments.
 Security code