+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / SitefinityLabel Attribute

SitefinityLabel Attribute

4 posts, 0 answered
  1. Devin
    Devin avatar
    16 posts
    Registered:
    27 Aug 2013
    12 Jan
    Link to this post

    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

  2. Sabrie Nedzhip
    Sabrie Nedzhip avatar
    534 posts
    Registered:
    23 Sep 2016
    15 Jan
    Link to this post
    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
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  3. Devin
    Devin avatar
    16 posts
    Registered:
    27 Aug 2013
    16 Jan in reply to Sabrie Nedzhip
    Link to this post

    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

  4. Sabrie Nedzhip
    Sabrie Nedzhip avatar
    534 posts
    Registered:
    23 Sep 2016
    26 Jan
    Link to this post
    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";
                }
            }
        }
    }

    5. Build the solution
    6. Register the control in the Toolboxes using Thunder as described in this article: http://docs.sitefinity.com/thunder-register-a-widget
    7. Restart the application

    After performing the above you will be able to drop the custom navigation widget on the page. If the Title property is not set in the widget designer the widget will display the default value that is defined in the InitializeControls() method. If you enter a value in the Title field in the designer, this value will be displayed by the SitefinityLabel control.

    Regards,
    Sabrie Nedzhip
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
4 posts, 0 answered