- Introduction
- Add the Link Collection property
- Control Link Collection rendering
- Good to Know - Link Collection property
Introduction
In this How To we shall demonstrate some ways in which the Link Collection property can be used. It is now possible to save a collection of links on a page, not only individual links. This is a useful feature, for example, if you want to create link lists for related pages.
Add the Link Collection property
Add the Link Collection property type to a page type:
In edit mode Add the links:
Control Link Collection rendering
You can use the EPiServer Property control to render the LinkCollection (the Property control will render the items as an unordered list):
<EPiServer:Property ID="Property1" runat="server" PropertyName="EventsRoot" CssClass="MyLinks" />
Alternatively, display the links with the ASP.NET repeater control to render the items (can be utilized to have more control over rendering):
<asp:Repeater runat="server" ID="linkRepeater"> <HeaderTemplate><h2>Links</h2></HeaderTemplate> <ItemTemplate> <a href='<%# (Container.DataItem as LinkItem).Href %>' target='<%# (Container.DataItem as LinkItem).Target %>' title='<%# (Container.DataItem as LinkItem).Title %>'> <%# (Container.DataItem as LinkItem).Text %> <br /> </a> </ItemTemplate> </asp:Repeater>One way to get the links from the CurrentPage in Code behind:
if (!IsPostBack) { if (CurrentPage["RelatedLinks"] != null) { LinkItemCollection links = CurrentPage.Property["RelatedLinks"].Value as LinkItemCollection; linkRepeater.DataSource = links; linkRepeater.DataBind(); } }