Conditionally Display Navigation Links
I've been at this all day, something I thought would be simple turn out to no be so simple. I'm trying to conditionally display a navigation link but it either doesn't display at all, displays all the time, or the href & target are not evaluated.
One of my issues comes in the form of Eval("Attributes[LocationID]") != "" not being evaluated properly. It no matter what comes up empty, yet the evals right after will have the proper value. I'm just not seeing what I need to do to get it to only display when the Attributes[LocationID] is nonempty.
01.
<%@ Control Language="C#" %>
02.
<%@ Import Namespace="Telerik.Sitefinity.Web.UI.NavigationControls.Extensions.LightNavigationControlTemplate" %>
03.
<%@ Import Namespace="Telerik.Sitefinity.Web.UI.NavigationControls" %>
04.
<%@ Register Assembly="Telerik.Sitefinity" TagPrefix="navigation" Namespace="Telerik.Sitefinity.Web.UI.NavigationControls" %>
05.
<%@ Register Assembly="Telerik.Sitefinity" TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" %>
06.
07.
<
sf:ResourceLinks
runat
=
"server"
UseEmbeddedThemes
=
"true"
Theme
=
"Basic"
>
08.
<
sf:ResourceFile
Name
=
"Telerik.Sitefinity.Resources.Themes.Basic.Styles.nav.widget.css"
Static
=
"true"
/>
09.
</
sf:ResourceLinks
>
10.
11.
<
navigation:SitefinitySiteMapDataSource
runat
=
"server"
ID
=
"dataSource"
/>
12.
13.
<
sf:SitefinityLabel
id
=
"title"
runat
=
"server"
WrapperTagName
=
"div"
HideIfNoText
=
"true"
HideIfNoTextMode
=
"Server"
/>
14.
<
div
class="sfNavWrp sfNavVerticalWrp <%= this.GetCssClass() %>">
15.
<%-- responsive design section - renders templates for the responsive design--%>
16.
<
navigation:NavTransformationTemplate
runat
=
"server"
TransformationName
=
"ToToggleMenu"
TemplateName
=
"ToggleMenu"
/>
17.
<
navigation:NavTransformationTemplate
runat
=
"server"
TransformationName
=
"ToDropDown"
TemplateName
=
"Dropdown"
/>
18.
<%--end of the responsive design section --%>
19.
20.
<
ul
class
=
"sfNavVertical sfNavList"
>
21.
<
navigation:NavigationContainer
runat
=
"server"
DataSourceID
=
"dataSource"
>
22.
<
Templates
>
23.
<
navigation:NavigationTemplate
>
24.
<
Template
>
25.
<
sf:Conditional
If='<%# Eval("Attributes[LocationID]") != "" %>' >
26.
<
Then
>
27.
<
li
id='<%# Eval("Id") %>'>
28.
<
a
runat
=
"server"
href='<%# Eval("ParentNode.Attributes[LocationID]") != "" ? NavigationUtilities.ResolveUrl(Container.DataItem) + "?
locationId
=
" + Eval("
ParentNode.Attributes[LocationID]") : NavigationUtilities.ResolveUrl(Container.DataItem) %>'
29.
target='<%# NavigationUtilities.GetLinkTarget(Container.DataItem) %>'>
30.
<%# Eval("Title")%> <%# Eval("Attributes[LocationID]") %>
31.
</
a
>
32.
</
li
>
33.
</
Then
>
34.
</
sf:Conditional
>
35.
</
Template
>
36.
<
SelectedTemplate
>
37.
<
sf:Conditional
If='<%# Eval("Attributes[LocationID]") != "" %>' >
38.
<
Then
>
39.
<
li
id='<%# Eval("Id") %>'>
40.
<
a
runat
=
"server"
href='<%# Eval("ParentNode.Attributes[LocationID]") != "" ? NavigationUtilities.ResolveUrl(Container.DataItem) + "?
locationId
=
" + Eval("
ParentNode.Attributes[LocationID]") : NavigationUtilities.ResolveUrl(Container.DataItem) %>'
41.
target='<%# NavigationUtilities.GetLinkTarget(Container.DataItem) %>'>
42.
<%# Eval("Title")%> <%# Eval("Attributes[LocationID]") %>
43.
</
a
>
44.
</
li
>
45.
</
Then
>
46.
</
sf:Conditional
>
47.
</
SelectedTemplate
>
48.
</
navigation:NavigationTemplate
>
49.
</
Templates
>
50.
</
navigation:NavigationContainer
>
51.
</
ul
>
52.
</
div
>
Hello,
Can you please check this forum post and try the suggestion there:
http://www.sitefinity.com/developer-network/forums/developing-with-sitefinity-/if-statement-in-widget-template#QU7lfvcSLUGIY9ImgmRuFQ
As suggested in the above forum post please try to cast the value of the custom text field to string and then check if the value is empty string.
Regards,
Sabrie Nedzhip
Telerik
I've already done that, doesn't change anything. I still have the issue of it not evaling cast or not.