Hello there
I have built a Custom data source for a side navigation bar (which is outputted via a Hierarchical viewer).
It returns the current pages parent, siblings and children (one level). Here's the code:
protected override object GetDataSourceFromDB()
{
// Initializes the data properties according to the filter settings
if (SourceFilterControl != null)
{
SourceFilterControl.InitDataProperties(this);
}
List<int> IncludeDocumentIds = new List<int>();
// get parent
if (!CurrentDocument.IsRoot())
{
if (!CurrentDocument.Parent.IsRoot())
{
IncludeDocumentIds.Add(CurrentDocument.Parent.DocumentID);
}
}
// include current page children
if (CurrentDocument.NodeHasChildren)
{
foreach(var c in CurrentDocument.Children)
{
IncludeDocumentIds.Add(c.DocumentID);
}
}
// include current page siblings
if(CurrentDocument.Parent != null)
{
foreach(var s in CurrentDocument.Parent.Children)
{
IncludeDocumentIds.Add(s.DocumentID);
}
}
string parentsids = string.Join(",", IncludeDocumentIds);
// create where condition
var where = new WhereCondition("DocumentID in (" + parentsids + ") and DocumentMenuItemHideInNavigation = 0");
// Loads the data. The WhereCondition and OrderBy properties are inherited from the parent class.
DataSource = DocumentHelper.GetDocuments(standardPageName)
.Where(where)
.Where(WhereCondition)
.Columns(new String[] { "DocumentID", "NodeAliasPath","NodeLevel","DocumentName", "NodeParentID", "NodeID", "DocumentMenuItemHideInNavigation"})
.OrderBy(OrderBy)
.TypedResult;
return DataSource;
}
This has worked OK until people started adding linked pages and now I am getting some weird results
I have a page Level 1 - 1 and that has a child page of Level 2 - 1.
I created a linked page of Level 2 - 1 and selected it's parent as Level 1 - 2
However whenever I view Level 1 - 1 or Level 1 - 2 both the original and the linked page (Level 2 - 1) appear in the menu (I only want the relevant child to appear)
So for example when I select Level 1 - 1 I get
Home
Level 1 - 1 (selected)
Level 2 - 1
Level 1 - 2
Level 2 - 1 (linked)
Level 1 - 3
Level 1 - 4
When I want to get just
Home
Level 1 - 1 (selected)
Level 2 - 1
Level 1 - 2
Level 1 - 3
Level 1 - 4
How can I alter my datasource to take these linked pages into account?
Many Thanks
Tracey