自定义 SharePoint 导航 2 层深度

发布于 2024-07-27 18:54:12 字数 607 浏览 1 评论 0原文

我有一个简单的网站,由一个根网站和 2 个子网站组成。

现在我希望所有 3 个站点的导航完全相同,内容如下:

根站点 | 子站点 1 | 子站点 2

当前选定的站点突出显示。

我几乎可以使用 asp:repeater 控件和 Portalsitemapprovider 手动完成此操作。 问题是我可以仅获取导航上的根站点(将 ShowStartingNode 设置为 True)或仅获取子站点,但我无法同时获取两者。

我知道如果您使用 sharepoint:aspmenu 控件并将 staticdisplaylevels 设置为 2,则可以同时获得两者,但我不喜欢该控件吐出的混乱代码。 基本上我想模拟这个包含在我自己的兼容 CSS 中的控件行为。 有任何想法吗?

  • 另外,作为补充,是否有人对我如何拥有它有任何想法,因此如果 subsite1/2 有后续子站点/页面,则无论用户在层次结构中导航多少层,它仍然会突出显示相关的 subsite1 或子站点2? 我当前的方法将 currentnode 与每个提供程序节点进行比较,以确定应突出显示哪些节点,但是一旦用户导航离开每个子网站的登录页面,这将不起作用。

谢谢!

I have a simple site consisting of a root site with 2 child sites.

Now I want the navigation for all 3 sites to be exactly the same and read:

Root Site | Child Site 1 | Child Site 2

With the currently selected site highlighted.

I have been able to nearly do this manually using an asp:repeater control and portalsitemapprovider. The problem is I can either get just the Root Site on the navigation (set ShowStartingNode to True) or just the child sites, I can't get both.

I know you can get both if you use a sharepoint:aspmenu control and set staticdisplaylevels to 2 but I don't like the messy code this control spits out. Basically i want to emulate this controls behaviour wrapped in my own compliant css. Any ideas?

  • Also as an addition does anyone have any ideas on how I can have it so if subsite1/2 have subsequent subsites/pages, it doesn't matter how many levels deep in the hierarchy a user is navigating, it still highlights the relevant subsite1 or subsite2? My current method compares currentnode with each of the providers nodes to work out which should be highlighted, but this doesn't work once the user has navigated away from the landing page of each subsite.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

金橙橙 2024-08-03 18:54:12

我认为你必须从根开始并在第一个中继器中渲染该节点,然后使用根的子节点作为第二个中继器的数据源,类似于:

<asp:Repeater runat="server" ID="MenuRepeater" 
DataSourceID="MainNavigationDataSource">

<HeaderTemplate>
  // code here
</HeaderTemplate>

<ItemTemplate>
  // code here
<asp:Repeater runat="server" ID="ChildMenuRepeater"
DataSource='<%# ((SiteMapNode)Container.DataItem).ChildNodes %>'>

<HeaderTemplate>
  // code here
</HeaderTemplate>

<ItemTemplate>
  // code here

</ItemTemplate>

</ItemTemplate>

对于你的第二个问题,我认为(如果我理解正确的话)您可以使用 SiteMapNode.IsDescendantOf() 方法,但我记得这在 SharePoint 中不起作用,因此我使用此类代码来检查节点是否是“活动”节点:

string CurrentContextUrl = SPUtility.GetPageUrlPath(HttpContext.Current);
Uri CurrentUri = new Uri(CurrentContextUrl);
bool Active = CurrentUri.LocalPath.Equals(currentNode.Url);

希望它能以某种方式提供帮助:-)

I think you have to start at the root and render that node in a first repeater and then use the childnodes of the root as a datasource for a second repeater, something like:

<asp:Repeater runat="server" ID="MenuRepeater" 
DataSourceID="MainNavigationDataSource">

<HeaderTemplate>
  // code here
</HeaderTemplate>

<ItemTemplate>
  // code here
<asp:Repeater runat="server" ID="ChildMenuRepeater"
DataSource='<%# ((SiteMapNode)Container.DataItem).ChildNodes %>'>

<HeaderTemplate>
  // code here
</HeaderTemplate>

<ItemTemplate>
  // code here

</ItemTemplate>

</ItemTemplate>

For your second question, I think (if I understand it correctly) that you could use SiteMapNode.IsDescendantOf() method but I somehow recall that that will not work in SharePoint so I have used this sort of code to check if a node is the "active" node:

string CurrentContextUrl = SPUtility.GetPageUrlPath(HttpContext.Current);
Uri CurrentUri = new Uri(CurrentContextUrl);
bool Active = CurrentUri.LocalPath.Equals(currentNode.Url);

Hope it helps out somehow :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文