0

I create field of type hyperlink in 2sxc dnn module.

Now if I use this in razor script i get URL pointing to this page and this is OK.

eg:
@Content.LinkFieldName

But now I need to create some kind of navigation to show me all child pages of this link. Haw, I can get this links?

eg:
foreach(var page in Content.LinkFileldName.GetChildren???){
    <li>@page.Name</li>
}
J King
  • 4,108
  • 10
  • 53
  • 103
Jernej Pirc
  • 504
  • 1
  • 4
  • 13

1 Answers1

1

This is one way: First, get DotNetNuke TabInfo of page (call function with Content.LinkFieldName) :

public static TabInfo GetTabByUrl(string url){
    foreach(var tab in TabController.GetPortalTabs(0, -1, false, true)){
        if (tab.FullUrl==url) return tab;
    }
    return null;
}

Now you have TabInfo of page url and make another function get children:

public static List<TabInfo> GetChildren(TabInfo ti){
    var list = new List<TabInfo>();
    foreach(var tab in TabController.GetPortalTabs(0, -1, false, true)){
        if (ti.TabID==tab.ParentId) list.Add(tab);
    }
    return list;
}

And now all call all together to list children...

<ul>
@foreach(var page in GetChildren(GetTabByUrl(Content.LinkFieldName))){
    <li><a href="@page.FullUrl">@page.TabName</a></li>
}
</ul>

This is my using namespaces:

@using System
@using ToSic.SexyContent
@using DotNetNuke.Entities.Tabs
Jernej Pirc
  • 504
  • 1
  • 4
  • 13
  • I somebody have some cleaner "linq" way, please post another answer – Jernej Pirc May 24 '16 at 07:20
  • I like this. A few notes that may improve the solution: When you access the field using the `DynamicEntity` (which allows quick `@Content.Page`) then you will always receive a resolved link. But internally pages are usually entered using "page:75" or similar. If you want to get the "real" data in the field, you can access the EAV entity using either `AsEntity(Content)` or when you're looping objects, don't cast to AsDynamic. The IEntity has a `GetBestValue(...)` command, which will deliver the real value inside the system. Then you would have the page number to work with. – iJungleBoy May 24 '16 at 15:49