Kentico 7 hide editable text if it's empty

后端 未结 2 1360
青春惊慌失措
青春惊慌失措 2021-01-13 14:42

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 edi

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-13 15:31

    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 == "") ? false : true;
        } 
    
        return isPopulated;
    }
    

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

    JavaScript Method

    The webcontainer needs an id, example:

    Headline

    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

    structure here.

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

提交回复
热议问题