Show/ Hide repeater webpart based on parent 'show webpart' value?

Dcode warner asked on October 27, 2018 08:59

I have a checkbox Boolean field "ShowWebPart" on a parent page. Is there a way to use the 'visible condition' or the 'where condition' in a repeater so that it gets the value of the 'ShowWebPart' field that exists only on the parent page? I'm trying to make this section on the front end visible only if the checkbox is checked on the parent's page in the admin pages. The parent and child uses two different pageTypes and they are already selected in the repeater.

I know it's possible to use this formula, but it uses the path names and suppose the name changes? Document["parent/child"].getvalue("ShowWebPart")

Unfortunately in the visible condition it returns nothing. And I don't know why 'ShowWebPart =1 'in the Where condition throws an error.

Correct Answer

Dcode warner answered on October 28, 2018 07:22

For Peter's response. I am able to get the correct document name of the 'Parent Page' using any of the following: {%CurrentDocument.Children.Where("DocumentName = 'Parent Page'") #%}
{%CurrentDocument.Children.Where("DocumentName = 'Parent Page'").FirstItem #%}
{%CurrentDocument.AllChildren.Where("DocumentName = 'Parent Page'").FirstItem #%}

However last part GetValue("showWebpart",false) returned false no matter if the checkbox is set as true/false. Next I tried to see if I can get the NodeID of the parent page using the same code. Which was successful.

{%CurrentDocument.Children.Where("DocumentName = 'Parent Page'").FirstItem.GetValue("NodeID") #%}

Somehow targeting the field name value returned nothing. Which means it's probably not being targeting. So I tried using'.WithAllData' in the script and I got the result.So for anyone who's interested. This is probably is what you need:

Parent Page Value:{%CurrentDocument.Children.WithAllData.Where("DocumentName = 'Parent Page''").FirstItem.GetValue("showWebpart") #%}

Thanks guys

0 votesVote for this answer Unmark Correct answer

Recent Answers


Peter Mogilnitski answered on October 27, 2018 12:22 (last edited on October 27, 2018 12:25)

You can put into repeater web part visibility condition macro like: {%!String.IsNullOrEmpty(CurrentDocument.Parent.GetValue("showWebpart"))#%}

0 votesVote for this answer Mark as a Correct answer

Dcode warner answered on October 27, 2018 17:25

Okay. This script looks like what I've been trying to do. thanks you However It's not targeting the "parent page", Rather the "root".

SO I tested with: {% CurrentDocument.DocumentName #%} in the repeater to see what's the current document name is. It returned "Home". I guess because the repeater exists on the home page.

Do you know how I can target the 'Parent page'. Which is a child of 'Home'. That's where the field exist.

Root
-- Home
-----Parent Page
------Child
------Child
------Child

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on October 28, 2018 02:58 (last edited on October 28, 2018 02:28)

Not quite sure I follow. if you are on home and you want to get direct children, :

{%CurrentDocument.Children.Where("DocumentName = 'Parent Page'").FirstItem.GetValue("showWebpart",false)#%}

or you can use CurrentDocument.AllChildren

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on October 28, 2018 05:10

First specify what page you are actually on, the CurrentDocument. Is is the /home page? I'm assuming so, what this means is CurrentDocument.Parent is the root of the website.

If you want to reference the parent of the document being rendered i.e. /home/parent-page/child-1 which would be /home/parent-page, you do something like:

Documents[NodeAliasPath].Parent.GetValue("showWebpart")

0 votesVote for this answer Mark as a Correct answer

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