Copied to clipboard

Flag this post as spam?

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


  • rendervouz 6 posts 126 karma points
    Aug 11, 2016 @ 09:25
    rendervouz
    0

    Check if a property is exist but empty/has no value

    I'm using Umbraco 7

    I was trying to only show the item.content and item.file only if it has value. But if user didn't upload/input any text it shouldn't be showing.

    I've tried using this code but it still shows the content and download button despite the item has no file/content to show

    <!-- Check first if content or file exists -->
    @if(item.content!=null){
        <a href="#@item.Id" data-toggle="collapse">Lihat selengkapnya &raquo;</a>
        <div id="@item.Id" class="collapse">
        <p>@item.content</p>
    <!-- Check if file exists -->   
        @if(item.file!=null){
           <p>
              <a href="@item.file" class="btn btn-warning">Download</a>
           </p>
        }
    }
    

    Is there any other way to check if a property is exist but has no value/empty?

    Thanks!

  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    Aug 11, 2016 @ 09:44
    Dennis Aaen
    102

    Hi rendervouz,

    You could use:

    @if(item.HasValue("file")){
           <p>
              <a href="@item.file" class="btn btn-warning">Download</a>
           </p>
    }
    

    Then if the field has a value then it will be outputted.

    Hope this helps,

    /Dennis

  • rendervouz 6 posts 126 karma points
    Aug 12, 2016 @ 02:25
    rendervouz
    0

    This solves the problem. Many thanks!

  • 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