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'") |(identity)GlobalAdministrator%}

Thanks guys

0 votesVote for this answer Unmark Correct answer

Recent Answers


Peter Mogilnitski answered on October 27, 2018 12:22 (last edited on December 10, 2019 02:31)

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

0 votesVote for this answer Mark as a Correct answer

Dcode warner answered on October 27, 2018 17:25 (last edited on December 10, 2019 02:31)

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 |(identity)GlobalAdministrator%} 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 December 10, 2019 02:31)

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)|(identity)GlobalAdministrator%}

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.