Search code examples
kentico

Set webpart visibility based on page category in Kentico


I have a page with a static HTML web part and want to set its visibility based on the value of the page category. If the category = "ABC" then make it visible, if not make it invisible. The category value was set through the Properties tab. I've tried these 2 macro below, but both didn't work. Thanks for your help!

{%if(CurrentDocument.Categories.DisplayNames=="ABC"){ return true; } else { return false; } #%}

or

{%if(CurrentDocument.Categories.DisplayNames.Contains("ABC")){ return true; } else { return false; } #%}

Solution

  • You can do it with the following macro (and there is no need for IF condition):

    {% CurrentDocument.IsInCategories("ABC;ABCD") %}
    

    Multiple categories can be listed with a semicolon.