简体   繁体   中英

Relative URLs in Sharepoint master page

I have a master page with tabs. The tabs are defined by the following sitemap file:

<siteMap>
    <siteMapNode title="Home" url="~/" >
        <siteMapNode title="Schedule" url="~/Pages/Tab2.aspx"/>      
        <siteMapNode title="Deliverables" url="~/Pages/Tab3.aspx"/>
        <siteMapNode title="My Items" url="~/Pages/Tab4.aspx"/>
        <siteMapNode title="Management" url="~/Pages/Tab5.aspx"/>
        <siteMapNode title="Working Docs" url="~/Pages/Tab6.aspx"/>
    </siteMapNode>
</siteMap>

The problem is that on my subsites, clicking on a tab keeps taking me back to the root. For example, I want the schedule link to go to http://Server/Subsite/Pages/Tab2.aspx . Instead, what I am getting is http://Server/Pages/Tab2.aspx . I read that having a tilde at the beginning of the link would solve this problem but it doesn't.

I spent HOURS looking for the answer to this question, and it turns out there IS one, it's just annoying. You can use the ProjectProperty tag in WSS sites AND MOSS sites, and one of the possible parameters for ProjectProperty gives you the subsite's URL.

<SharePoint:ProjectProperty Property="Url" runat="server"/>

That outputs a string literal with the value of the subsite URL. So, for example, you can do this (note that you need to use single-quotes for the src='' or href='' attribute of the actual HTML tag):

<a href='<SharePoint:ProjectProperty Property="Url" runat="server"/>/pages/Tab2.aspx'>

Hope it helps! For a listing of other possible values for ProjectProperty, check out this guy's page (which is where i found my original answer!)

I was looking for an answer to do this for a long time... I want to package my site as a Site Template and having absolute URLs was not an option... I need them to be relative to what ever the site URL is... whether it is at the root of MOSS or a sub-site deep down in the structure...

I found the following to work:

Script Tags:

<script type="text/javascript" src='<asp:Literal runat="server" 
               Text="<% $SPUrl:~Site/appBin/js/jquery.min.js %>" />'></script>

Style sheet (Method suggested above by user385947):

<link rel="stylesheet" type="text/css" 
       href="<% $SPUrl:~Site/appBin/css/jquery-ui.css %>" />

Hope this helps others...

您正在寻找〜站点令牌, 这里是WSS定制的URL令牌列表。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM