Dynamic path in cmsrepeater

Lennard van Diggelen asked on September 9, 2016 13:14

Hi There,

Is it possible to add a dynamic path to a CMSRepeaer based on the value of an other CMSRepeaer? Below breaks the code and I cannot achieve the right result.

<cms:CMSRepeater runat="server" DelayedLoading="true" ID="MainMenu" Path='<%#Eval("NodeAliasPath") %>' ClassNames="CMS.MenuItem" MaxRelativeLevel="2" WhereCondition="NodeLevel > 1" HideControlForZeroRows="False" ZeroRowsText="There are no menu pages." CacheDependencies="##DEFAULT##" >

Thanks in advance!

Correct Answer

Brenden Kehren answered on September 9, 2016 18:37

I'd agree with Kristian, don't nest your repeater. To get around the issue you're having with the hierarchical viewer, simply add the MenuItemGroup field to the other page types being used in the viewer. You can hide that field in those other page types but keep in mind it will only get the page types with %main% in that field so the other page types won't be found if there is no value.

If you're using it specifically for navigation, I'd use a different approach and get rid of that field all together and create a Category called Navigation and add new categorizes below it like Top, Left, Main, Footer, Right, etc. Then assign those categories to the pages you wish to display in the navigation. There is a drawback to this though, in the repeaters and such, you can only select one category.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Kristian Bortnik answered on September 9, 2016 13:36

Is it possible? Yes.

One way of doing it is to use a OnItemDataBound event on the outer repeater.

protected void elemRpt_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
    var ctrl = e.Item.FindControl("MainMenu") as CMSRepeater;
    ctrl.Path = (string)((DataRowView) e.Item.DataItem)["NodeAliasPath"];
}

You can then remove the Path property from the inner repeater.

Is this best practice? No.

It is best not to nest repeaters. Use a Hierarchical viewer or a similar control. Here's how to use hierarchical transformations, and here's how to create a mega menu.

1 votesVote for this answer Mark as a Correct answer

Lennard van Diggelen answered on September 9, 2016 13:47

Hi Kristian,

I tried the hierarchical but i had a major issue with the where condition. In my aspx file i can use WhereCondition="MenuItemGroup Like '%main%'" but i can never make this work in the where condition of the webpart. The whole website webpart understand this query.

Or is there some way else I can achieve this wherecondition within the webpart?

Thanks!

0 votesVote for this answer Mark as a Correct answer

Lennard van Diggelen answered on September 9, 2016 21:06

Thanks guys,

I fixed it with the hierarchical transformation eventually because of your points concerning performance.

Thank You!

1 votesVote for this answer Mark as a Correct answer

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