4

I have an editable text web part on a page template. It has a custom HTML envelope before and after the text. How can I hide the whole thing, envelope included, if the editable text is empty?

I need to hide it because the envelope adds stylized markup that shouldn't be visible when there is no text.

Can it be done with a K# snippet on the Visible property? I'm unclear how interrogating a document's property works.

Thanks!

Tyler Brinks
  • 1,201
  • 1
  • 14
  • 24
  • 1
    [Reported here](http://devnet.kentico.com/Forums/f65/t36410/Editable-Image-Visibility.aspx) that a fix was put in place to fix this problem. What version are you using? – JSuar Dec 23 '13 at 13:50
  • @JSuar I'm using the Azure gallery template which is v 7.0.11 – Tyler Brinks Dec 23 '13 at 16:11
  • Based on the forum, it looks like you don't have the fix. Is there anyway you could update? – JSuar Dec 23 '13 at 16:13
  • @JSuar I've tried it now in version 7.0.34 and it's still not working as I'd expect. The only solution I've come up with (without resorting to code) is to use multiple templates with the same field names. – Tyler Brinks Dec 28 '13 at 20:37
  • No luck with any of the solutions? – JSuar Dec 30 '13 at 20:13
  • None yet. I may explore a custom web part that inherits from the editable text region. – Tyler Brinks Dec 31 '13 at 21:44

2 Answers2

3

Try this as the "Visible" property:

{% (ViewMode != "LiveSite") || (CMSContext.CurrentDocument.editabletext != "") #%}

Change "editabletext" to whatever you have for your web part control ID.

Quentin Hayot
  • 7,786
  • 6
  • 45
  • 62
  • @tyler this option works great as a macro solution! Make sure you don't have any default text set in the webpart configuration. – Brenden Kehren Aug 19 '15 at 13:46
  • I set it to hide in preview mode too `{% (ViewMode != "LiveSite" && ViewMode != "Preview") || (!string.IsNullOrWhiteSpace(CMSContext.CurrentDocument.editabletext)) #%}` – jaypeagi Nov 17 '16 at 10:21
0

I'm not familiar with Kentico but these solutions might help. They may not address your problem specifically but might aid in a solution.

CMSEditableImage Extension Method

I came up with a way to check this, I added an extension method for the CMSEditableImage class that takes the CurrentPage PageInfo object to check the value of the editable region, don't know if this is the best way or not, but here's the code.

public static bool IsPopulated(this CMSEditableImage editableImage, PageInfo currentPage)
{
    bool isPopulated = false;

    string value = currentPage.EditableItems.EditableRegions[editableImage.ID.ToLower()].ToString();

    if (!string.IsNullOrEmpty(value))
    {
    value = value.ToUpper();
    isPopulated = (value == "<IMAGE><PROPERTY NAME=\"IMAGEPATH\"></PROPERTY></IMAGE>") ? false : true;
    } 

    return isPopulated;
}

via http://devnet.kentico.com/Forums/f19/fp5/t4454/Empty-CMSEditableImage.aspx

JavaScript Method

The webcontainer needs an id, example:

<h2 id="webpart-header">Headline</h2>

Then I have a small javascript function that is attached in an external js file:

/* Hide Webcontainer via javascript if empty*/
function hideLayer(element) {
    elem = document.getElementById( element );
    elem.style.display = "none";
}

Now in the wep part configuration, at no data behaviour, you uncheck the checkbox and call the js function by entering following script in the no record found text: hideLayer("webpart-header");

Whereby webpart-header the id name of your container is. You could also have a more complex <div> structure here.

via http://devnet.kentico.com/Forums/f22/fp3/t4180/Webcontainer-and-hide-if-no-data.aspx

JSuar
  • 21,056
  • 4
  • 39
  • 83
  • the OP was looking for a solution regarding editable text not an image. Yes he can get ideas from it but honestly, neither of those solutions are very good. Especially since the OP was specifically looking for a K# macro solution and not C# or JavaScript. – Brenden Kehren Aug 19 '15 at 13:51
  • Understood. Just looking to provide some help. Down vote if you think it's of no help to others that might come across this question. – JSuar Aug 19 '15 at 17:08