Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
Im trying apply a navigation structure depending on the document type alias used.
Im checking if the pages have any children, and then the doc type alias.
Im running in to problems with duplicate nodes.
Any help would be grateful.
Martin
@foreach (var childPage in home.Children.Where("Visible")) { if (childPage.Children.Any()) { if(childPage.DocumentTypeAlias == "DocType-1" ) { <li class=""><a href="">Doc Type 1</a></li> } if(childPage.DocumentTypeAlias == "DocType-2" ) { <li class=""><a href="">Doc Type 2</a></li> } else { <li class=""><a href="">Any Doc Type</a></li> } } else { <li class=""><a href="">Any Doc Type</a></li> } }
Hi Martin,
Could you try this code and see if it works like you wanted it to work.
@{ var home = CurrentPage.AncestorOrSelf(1); foreach (var childPage in home.Children.Where("Visible")) { if (childPage.Children.Any()) { if(childPage.DocumentTypeAlias == "DocType1Alias" ) { <li class=""><a href="">Doc Type 1</a></li> } if(childPage.DocumentTypeAlias == "DocType2Alias" ) { <li class=""><a href="">Doc Type 2</a></li> } else { <li class=""><a href="">Any Doc Type</a></li> } } else { <li class=""><a href="">Any Doc Type</a></li> } } }
Hope this helps,
/Dennis
Reformating your code for readability, you're probably getting the duplicates due to the 2 if statements
Now consider your doctype is DocType-1. That would satisfy TURE for the first IF
if(childPage.DocumentTypeAlias == "DocType-1" ) { <li class=""><a href="">Doc Type 1</a></li> }
and also be rendered in the ELSE
if(childPage.DocumentTypeAlias == "DocType-2" ) { <li class=""><a href="">Doc Type 2</a></li> } else { <li class=""><a href="">Any Doc Type (can also be Doc Type 1 again)</a></li> }
Hence the double result.
Changing you're whole code block to this should fix things.
@foreach (var childPage in home.Children.Where("Visible")) { if (childPage.Children.Any()) { if(childPage.DocumentTypeAlias == "DocType-1" ) { <li class=""><a href="">Doc Type 1</a></li> } else if(childPage.DocumentTypeAlias == "DocType-2" ) { <li class=""><a href="">Doc Type 2</a></li> } else { <li class=""><a href="">Any Doc Type</a></li> } } else { <li class=""><a href="">Any Doc Type</a></li> } }
Also, the last else {} probably isn't needed. What would that render?
Thanks Ajay.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Multi If Statement for Document Type Alias
Hi,
Im trying apply a navigation structure depending on the document type alias used.
Im checking if the pages have any children, and then the doc type alias.
Im running in to problems with duplicate nodes.
Any help would be grateful.
Martin
Hi Martin,
Could you try this code and see if it works like you wanted it to work.
Hope this helps,
/Dennis
Reformating your code for readability, you're probably getting the duplicates due to the 2 if statements
Now consider your doctype is DocType-1. That would satisfy TURE for the first IF
and also be rendered in the ELSE
Hence the double result.
Changing you're whole code block to this should fix things.
Also, the last else {} probably isn't needed. What would that render?
Thanks Ajay.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.