Copied to clipboard

Flag this post as spam?

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


  • Carlos 338 posts 472 karma points
    Dec 06, 2013 @ 20:40
    Carlos
    0

    How do you check if a Multiline textblock (simple text editor) is empty?

    How do you check if a Multiline textblock (simple text editor) is empty in Umbraco using Razor?

    I have a property on an Image MediaType that I am pulling and outputting, however, when I check if the property is empty the check is not working, so it is still outputting.

    Here is my check below:

    <ul class="slides">
     @foreach(dynamic slideImage in mediaFolder.Children){
        var slideCaption = @slideImage.caption.ToString();
       <li>
    @*@if(slideImage.caption.GetType() != typeof(umbraco.MacroEngines.DynamicXml))*@
    @* @if(!String.IsNullOrWhiteSpace(@slideCaption))*@
    
    @if(@slideCaption != String.Empty){
    <img src="/imagegen.ashx?&[email protected]" title="@(slideImage.GetValue("caption"))" alt="@(slideImage.GetPropertyValue("altTag"))" data-caption="#@slideImage.Id"  />
    <p class="flex-caption" id="@slideImage.Id">@slideImage.GetProperty("caption")</p> 
    }
    else{Empty Property...supposedly}
        </li>                                          
           }
    </ul>

     

    It is not getting past my IF statement if the property box is empty.

    I have verified that the textblocks are empty but it seems like in Umbraco it property is not.

    Any help is greatly appreciated.

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 06, 2013 @ 21:03
    Jeavon Leopold
    0

    Hi Carlos,

    You have hit on a couple of annoying bugs in DynamicMedia here, below is my suggested workaround using uQuery

    Try this:

    <ul class="slides">
         @foreach(var slideImage in mediaFolder.Children){
    
             int mediaId;
             if (!int.TryParse(slideImage.Id, out mediaId))
             {
                 mediaId = 0;
             }
             var mediaItem = uQuery.GetMedia(mediaId);
             var imageCaption = string.Empty;
             if (mediaItem.HasProperty("caption"))
             {
                 imageCaption = mediaItem.GetProperty<string>("caption");
             }
    
           if(!string.IsNullOrEmpty(imageCaption)){
             <li>
               <img src="/imagegen.ashx?&[email protected]" title="@imageCaption" alt="@slideImage.altTag" data-caption="#@slideImage.Id"  />
               <p class="flex-caption" id="@slideImage.Id">@slideImage.caption</p> 
             </li>                                          
           } 
        }         
        </ul>
    

    Jeavon

  • Carlos 338 posts 472 karma points
    Dec 06, 2013 @ 21:26
    Carlos
    0

    the messed up thing is that we have a test website. The code I have above WORKS in the test site and now our Live site.  So I don't quite know if it is a bug.  The Umbraco versions are the same, The code in the Macro are the same.  I don't get it.

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 06, 2013 @ 21:42
    Jeavon Leopold
    0

    Probably the difference is content, the problem is cause by this issue http://issues.umbraco.org/issue/U4-579

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies