Search code examples
transformationweb-partsvisiblekentico

Kentico8 - Show / hide a webpart or transformation depending on path


On our website, we have a logo on top. What I want is the following:

If the website's path starts with: 'www.website.com/books' The Logo should be 'books.png'. If the website's path starts with anything else, it should be 'logo.png'

The logo is loaded in a repeater webpart. I can set the visibility of the books.png webpart to:

{%NodeAliasPath.StartsWith("/books/")#%}

Which works, The logo shows up if I go to, say, website.com/books and website.com/books/harry-potter, but I want the normal logo on any other website.

  • First I tried to make some sort of If statement in the transformation of the repeater itself. This way I will only need one webpart, that changes content depending on the path. But it looks like Kentico won't allow If statements inside a transformation. I still prefer an option like this, since it feels cleaner to me.

  • The other option is I make two repeaters, one with the normal logo.png, and one with books.png. But how would I hide the logo.png if the path starts with /books?

  • Or if anyone has another solution to this problem, let me know :)

Thanks.


Solution

  • Easiest option is to just have 2 repeaters or webparts for this so it's easily visible in the Design tab.

    Your visibility macro for the /books should be:

    {% CurrentDocument.NodeAliasPath.ToLower().Contains("/books") %}
    

    And for the other webpart you'd enter:

    {% !CurrentDocument.NodeAliasPath.ToLower().Contains("/books") %}