Conditionally Show Field in Custom Module Widget Template
I've created a custom module citation for academic references. Citations have, among other things, a title and an optional articleURL to link to the original article.
Is there a way for me to write the widget template so that, if the URL is not blank, render it as a link? With apologies for my PHP style pseudocode (new to sitefinity/.net), what I have in my head is something like:
if
(notEmpty(
'articleURL'
))
<a href=
"<%# Eval("
articleURL
")%>"
><%# Eval(
"Title"
)%></a>
else
<%# Eval(
"Title"
)%>
Hi Fitzgerald,
by default, the built-in widget template editor will strip any server side code so this approach unfortunately won't work.
However, I believe there are two ways to achieve the desired result.
You might be able to use the tertiary operator to hide a value, such as:
<%# Eval("Foo") == null ? "" : Eval("Foo") %>
Looks like that works for me! Thanks!
Is there documentation for the UI widgets in the 'sf' namespace? I'm looking for some kind of reference to all the <sf:...> controls.
Hello,
To create an instance of the control, declare the appropriate namespace in your user control.
You should use the following source code and change the tag prefix and namespace to what you want to be used.
<%@ Register TagPrefix="sf" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
Hey I know this is a couple years down the road, but I'm in need of this functionality. As a newbie programmer I really don't know how to implement an 'if/else' type of scenario, especially in Sitefinity.
What I have is a Featured Item that may or may not have a caption that shows up on hover. I built this module using Module Builder. There is a 'caption' field that they could enter a caption into. What I need though is to make it so that if the user doesn't enter a caption the code for the caption won't show up. I have this tiny bit of code as the caption
<
span
class
=
"caption simple-caption"
>
<
p
>(Simple Caption)</
p
>
</
span
>
<
telerik:RadListView
ID
=
"dynamicContentListView"
ItemPlaceholderID
=
"ItemsContainer"
runat
=
"server"
EnableEmbeddedSkins
=
"false"
EnableEmbeddedBaseStylesheet
=
"false"
>
<
LayoutTemplate
>
<
section
id
=
"boxContainer"
>
<
div
class
=
"boxes"
>
<
asp:PlaceHolder
ID
=
"ItemsContainer"
runat
=
"server"
/>
</
div
>
</
section
>
</
LayoutTemplate
>
<
ItemTemplate
>
<
article
class
=
"<%#Eval("
BoxStyle") %>" data-w="<%#Eval("DataW") %>" data-h="<%#Eval("DataH") %>">
<%#Eval("Content") %>
<
span
class
=
"caption simple-caption"
>
<%#Eval("Caption") %>
</
span
>
</
article
>
</
ItemTemplate
>
</
telerik:RadListView
>
I have created a module for bio information. I want to drop the widget on a page and only display items if they have values. Right now, regardless if there is data in the in the field, the label is still showing, ex:
Name : John Smith
University:
Phone: 412-214-5433
I want to hide the University label because it's empty. Here is the code from the widget template for that particular field/label.
<div class='sfitemShortTxtWrp'>
<sf:SitefinityLabel runat="server" Text='University:' WrapperTagName="div" HideIfNoText="true" CssClass="sfitemFieldLbl bio-text-dt" />
<sf:SitefinityLabel runat="server" Text='<%# Eval("University")%>' WrapperTagName="div" HideIfNoText="true" CssClass="sfitemShortTxt bio-text-dd" data-sf-field="University" data-sf-ftype="ShortText"/>
</div>
@Kyle
What about something like this...link the visibility of the prev label to the text of the University field
<
sf:SitefinityLabel
runat
=
"server"
Text
=
'University:'
WrapperTagName
=
"div"
CssClass
=
"sfitemFieldLbl bio-text-dt"
Visible='<%# !String.IsNullOrEmpty(Eval("University").ToString()) %>' />