SitefinityLabel Attribute
Hi, we have a SitefinityLabel in one of our navigation widget templates. We would like the SitefinityLabel to display the Title property from the navigation widget template designer (Advanced) if the property has been populated, or display a default title if the Title property was not populated in the widget designer. Is there an attribute for SitefinityLabel that would allow this? Something like DefaultIfNoText="My Title"?
<
sf:SitefinityLabel
id
=
"title"
runat
=
"server"
WrapperTagName
=
"div"
HideIfNoText
=
"true"
HideIfNoTextMode
=
"Server"
/>
Also, is there a reference for the Sitefinity controls? Working with them often feels like working in the dark.
Thanks,
Devin
Hello Devin,
The SitefinityLabel control does not have a property to display a default value if the Text property is empty.
What I can suggest is that you use the <sf:Conditional> control and render content depending on a condition. Please note that the "If" attribute in the <sf:Conditional> control should contain a boolean value.
Refer to the below forum post for a sample and more details on how to use the Conditional control:
http://www.sitefinity.com/developer-network/forums/developing-with-sitefinity-/if-statement-in-widget-template#QU7lfvcSLUGIY9ImgmRuFQ
You may also check the below KB article for more details on this:
http://www.sitefinity.com/developer-network/knowledge-base/details/how-to-render-different-content-in-the-widget-template-depending-on-the-related-items-count
Regards,
Sabrie Nedzhip
Telerik
Sabrie, thank you for your reply.
I'm struggling with implementing the <sf:Conditional> tag in the following scenario:
Widget Title Condition
How does one evaluate if the widget designer's Title property is populated (see the attached screenshot -- the property is under the widget designer's Advanced button)?
I'm looking to do something like the following where title is the property in the widget designer:
<
sf:Conditional
If='<%# title.Text!="" %>' runat="server">
<
Then
>
<
sf:SitefinityLabel
id
=
"title"
runat
=
"server"
/>
</
Then
>
<
Else
>
Related Documents
</
Else
>
</
sf:Conditional
>
(Eval("Title") does not work in the <sf:Conditional> tag because it evaluates the title of the navigation item that's being iterated through, not the widget designer title.)
Thanks,
Devin
Hello Devin,
I further researched this and it seems that it would not be possible to achieve the desired behavior using the Conditional control.
A possible solution would be to create a custom Navigation widget that extends the built-in Navigation widget. Then you will be able to access the Title property which is in the widget designer using this.Title and also the SitefinityLabel control that displays this property using this.TitleLabel.
In order to do this please perform the bellow steps:
1. Open the project in Visual Studio
2. Create a class that inherits from the LightNavigationControl class which is the built-in navigation widget class
3. Override the InitializeControls() and call the base.InitializeControls() method.
4. Add your custom logic for setting the value of the SitefinityLabel control to the Title property from the designer
Here is a sample for your convenience:
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
Telerik.Sitefinity.Web.UI.NavigationControls;
namespace
SitefinityWebApp
public
class
LightNavigationControlCustom : LightNavigationControl
protected
override
void
InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container)
base
.InitializeControls(container);
if
(
this
.Title !=
null
)
// sets the Title property from the designer to the TitleLabel control
this
.TitleLabel.Text =
this
.Title;
else
// sets the default value for the Title property to the TitleLabel control
// this value will be displayed if the Title is not set in the designer
this
.TitleLabel.Text =
"Default value"
;