Bind custom fields in widget templates

NEW TO SITEFINITY?

You can bind simple properties, like Integer, Boolean, or Lstring fields, in templates using the Eval statement. Helper methods in the NavigationUtilities class are provided in order to show links of Related data and media items. 

Use the following example to bind a custom field in a widget template:

<%@ Control Language="C#" %>
<%@ Import Namespace="Telerik.Sitefinity.Web.UI.NavigationControls.Extensions.LightNavigationControlTemplate" %>
<%@ Import Namespace="Telerik.Sitefinity.Web.UI.NavigationControls" %>
<%@ Register Assembly="Telerik.Sitefinity" TagPrefix="navigation" Namespace="Telerik.Sitefinity.Web.UI.NavigationControls" %>
<%@ Register Assembly="Telerik.Sitefinity" TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" %>
<sf:ResourceLinks ID="resourcesLinks2" runat="server" UseEmbeddedThemes="true" Theme="Basic">
<sf:ResourceFile Name="Telerik.Sitefinity.Resources.Themes.Basic.Styles.nav.widget.css" Static="true" />
</sf:ResourceLinks>
<navigation:SitefinitySiteMapDataSource runat="server" ID="dataSource" />
<sf:SitefinityLabel ID="title" runat="server" WrapperTagName="div" HideIfNoText="true" HideIfNoTextMode="Server" />
<div class="sfNavWrp sfNavHorizontalWrp <%= this.GetCssClass() %> <%= this.GetType() %>">
<%-- responsive design section - renders templates for the responsive design--%>
<navigation:NavTransformationTemplate runat="server" TransformationName="ToToggleMenu" TemplateName="ToggleMenu" />
<navigation:NavTransformationTemplate runat="server" TransformationName="ToDropDown" TemplateName="Dropdown" />
<%--end of the responsive design section --%>
<ul class="sfNavHorizontal sfNavList">
<navigation:NavigationContainer runat="server" DataSourceID="dataSource">
<Templates>
<navigation:NavigationTemplate>
<Template>
<li>
<a runat="server" href='<%# NavigationUtilities.ResolveUrl(Container.DataItem) %>' target='<%# NavigationUtilities.GetLinkTarget(Container.DataItem) %>'><%# Eval("Title") %></a>
<%--------------------------------- samples start -------------------------------------%>
<%--basic properties --%>
<div><%# Eval("Hint") %></div>
<%--urls to related data --%>
<img src='<%#NavigationUtilities.GetRelatedMediaLink(Container.DataItem, "HelpImage", "thumb80")%>' />
<%--urls to related data --%>
<a runat="server" href='<%# NavigationUtilities.GetRelatedDataItemLink(Container.DataItem, "Article") %>' target='<%# NavigationUtilities.GetLinkTarget(Container.DataItem) %>'>News Item</a>
<%--------------------------------- samples end ----------------------------------------%>
</li>
</Template>
<SelectedTemplate>
<li>
<a runat="server" class="sfSel" href='<%# NavigationUtilities.ResolveUrl(Container.DataItem) %>' target='<%# NavigationUtilities.GetLinkTarget(Container.DataItem, "HelpImage") %>'><%# Eval("Title") %></a>
</li>
</SelectedTemplate>
</navigation:NavigationTemplate>
</Templates>
</navigation:NavigationContainer>
</ul>
</div>

Want to learn more?

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?