Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Joseph 12 posts 32 karma points
    Nov 25, 2010 @ 01:27
    Joseph
    0

    Can you add control (if this do this) in a template?

    I have a template like this:

    <%@ Master Language="C#" MasterPageFile="~/umbraco/masterpages/default.master" AutoEventWireup="true" %>

    <asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
    <umbraco:Item field="text" runat="server"></umbraco:Item>
    </asp:Content>


    Is there a way to check if "text" has a value eg using pseudo code

    if(text.Length > 0)
    {
      <umbraco:Item field="text" runat="server"></umbraco:Item>
    }

  • Lachlann 344 posts 626 karma points
    Dec 10, 2010 @ 10:34
    Lachlann
    0

    I dont know of a way of doing this, but you can set a secondary feild to use if the specified feild is empty, you can also set some static text to use if neither of these feilds hold any content.

     

    <umbraco:Item field="bodyContent" useIfEmpty="abstract" textIfEmpty="There is no content available" recursive="true" runat="server"></umbraco:Item>
     

    Hope this helps

  • tentonipete 78 posts 223 karma points
    Dec 10, 2010 @ 15:05
    tentonipete
    0

    Firstly if there is no content then the control will not render, isn't that what you want?

    If you do want to do some kind of check you can do it in the code behind, check the status of a property and then set the control's visibility to be false.

    e.g.

    <umbraco:Item field="bodyText" runat="server" ID="bodyTextControl" />
    protected void Page_Init(object sender, EventArgs e)    
    {        
        var node = umbraco.presentation.nodeFactory.Node.GetCurrent();
    
        if (String.IsNullOrEmpty(node.GetProperty("bodyText").Value))
        {    
        bodyTextControl.Visible = false;    
        }
    }

     

    I'm guessing this would be more useful if you wanted to do some other check before rendering than checking that there is content though.

Please Sign in or register to post replies

Write your reply to:

Draft