Create link to Sitecore Item

前端 未结 6 1894
Happy的楠姐
Happy的楠姐 2021-02-07 00:42

I know I have done this before but I can\'t seem to remember where or how.

I want to create a link to an Item in Sitecore. This code:

Sitecore.Data.Items         


        
相关标签:
6条回答
  • 2021-02-07 00:57

    You can render item link as below:

    Sitecore.Data.Items.Item itm = Sitecore.Context.Database.GetItem(someID);
    return Sitecore.Links.LinkManager.GetItemUrl(itm);
    
    0 讨论(0)
  • 2021-02-07 01:11

    If you are still using Sitecore 5.3, you can use this. Be warned this method is deprecated in Sitecore 6.0.

    string url = item.Paths.GetFriendlyUrl();
    
    0 讨论(0)
  • 2021-02-07 01:14

    You can do by this also:

    Item.Paths.FullPath
    

    It is same as:

    Sitecore.Links.LinkManager.GetItemUrl(item);
    
    0 讨论(0)
  • 2021-02-07 01:18

    Try this

      <asp:HyperLink ID="hlItem" runat="server">
    
        </asp:HyperLink>
    

    aspx.cs

       Sitecore.Data.Items.Item itm = Sitecore.Context.Database.GetItem("/sitecore/content/Home");
    
        hlItem.Navigateurl =sitecore.links.linkmanager.getitemurl(itm);
    
    0 讨论(0)
  • 2021-02-07 01:19

    You're needing this one, assuming you're running Sitecore v6 or anything more recent (tested with 8.2-6, should work with 9 too):

    Sitecore.Links.LinkManager.GetItemUrl(item);
    
    0 讨论(0)
  • 2021-02-07 01:19

    Your Web Control:

    <asp:HyperLink ID="HyperLinkItem" runat="server">
        Item
    </asp:HyperLink>
    

    Your Code:

    var homeItem = Sitecore.Context.Database.GetItem("/sitecore/content/Home");
    HyperLinkItem.NavigateUrl = Sitecore.Links.LinkManager.GetItemUrl(homeItem);
    
    0 讨论(0)
提交回复
热议问题