Copied to clipboard

Flag this post as spam?

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


  • Sam 79 posts 426 karma points
    Jan 26, 2016 @ 21:19
    Sam
    0

    condition statement based on content's published state... published vs not published.

    Hello,

    Im new to Umbraco, so this might seem like a simple question. thank you in advance.

    I would like to have a condition statement that renders a loop if the content is published, and if there is no content for that document type published it would render a message.

    The syntax for the statement is pretty straightforward, I just can't find the proper vocabulary to form the condition.

    here is my code... waiting for the condition. Thank you for you time.

    @if (){
    
        foreach (var item in Model.Content.Children(x=> x.IsVisible())){
            <div class='CareerCard'>
                <h1>@item.GetPropertyValue("jobTitle")</h1>
                @item.GetPropertyValue("jobDiscription")
                <hr>
                @item.GetPropertyValue("howToApplyText")
            </div>
        }
    }else{
        <p>There are currently no opportunities availible. Please check back at another time.</p>
    }
    
  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 26, 2016 @ 21:22
    Jeavon Leopold
    100

    I think if Model.Content.Children.Any() should do it. The PublishedContent API you are using will never contain unpublished items.

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 26, 2016 @ 21:24
    Jeavon Leopold
    0

    Actually you will need to add your condition so Model.Content.Children.Any(x => x.IsVisible())

  • Sam 79 posts 426 karma points
    Jan 27, 2016 @ 15:40
    Sam
    0

    was this statement listed anywhere in the documentation? I seem to be having trouble finding information on what should be pretty basic.

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 27, 2016 @ 17:37
    Jeavon Leopold
    0

    Not exactly, it is normal C#. The Any() method comes from Linq and the "filter" is a C# lambda expression

  • Sam 79 posts 426 karma points
    Jan 26, 2016 @ 21:26
    Sam
    0

    Good to know... That did the trick.

Please Sign in or register to post replies

Write your reply to:

Draft