Kentico 10 | Show webpart when webpart is checked

Dcode warner asked on September 28, 2017 22:01

I'm pretty sure witin the 'visibility' section for a webpart / zone in V7 we can place this script below using a boolean field type to show and hide a webpart / zone. But for some reason in V10 this code isn't working.

{% if (showOptionalContent == true) { return true; } else { return false; } #%}

Is there a more updated code for K10

Correct Answer

Rui Wang answered on September 29, 2017 00:31

If the parent (page type 1) and child pages (page type 2) are sharing the same template, and the field value exist on the child page type, then if you have the {% FieldName %} in a web part's HTML envelope (for example), then it should display nothing on parent, but display something on child page. You don't need to do anything special.

Also, I just noticed for the visible condition macro, you don't need {% if (showOptionalContent == true) { return true; } else { return false; } |(identity)GlobalAdministrator%} because it would be true or false or 0 or 1.

2 votesVote for this answer Unmark Correct answer

Recent Answers


Rui Wang answered on September 28, 2017 22:51

Can you first check if showOptionalContent does return a value by just put into into HTML {% showOptionalContent %}

Second, when you enter the macro for visibility, did you click on the black triangle to enter the code? When you do that, the single line text box should become a multi line box. If you directly pasted the macro in to the single line text box, the macro would not be evaluated.

0 votesVote for this answer Mark as a Correct answer

Dcode warner answered on September 28, 2017 23:33 (last edited on December 10, 2019 02:31)

@RuiWang Thanks for pointing me in the right directions. I did that earlier and nothing returned. So now I tired it with NodeID, and the value is that of the parent. So it's not reading from the specific subpage for some reason. How can I make it READ the CHILD PAGES. The BELOW only get the first page. But I like it to be more SPECIFIC because it wont ALWAYS be the first page. Can I specifiy by the Document Type?

{% Documents.WithAllData[CurrentDocument.Children[0].NodeAliasPath].GetValue("showGallery") |(identity)GlobalAdministrator%}

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.