Copied to clipboard

Flag this post as spam?

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


  • Lee M. Childress 14 posts 94 karma points
    7 days ago
    Lee M. Childress
    0

    So I have the following code:

        @if (Model.HasValue("departmentAlertMessage"))
        {
    <!-- DEPARTMENT ALERT BAR: START -->
                    <section class="page-header page-header-sm" style="background-color: #36454F; margin-bottom: 0">
                        <div class="container">
                            <div class="row">
                                <div class="col-md-12 order-2 order-md-1 align-self-center p-static">
                                    <h1><i style="padding-right: 10px;" class="text-color-light fa-solid fa-circle-exclamation"></i>@Model.Value("departmentAlertTitle", fallback: Fallback.ToAncestors)</h1><br />
                                                                    <p style="display: inline; color: #ffffff;">@Model.Value("departmentAlertMessage", fallback: Fallback.ToAncestors)</p>
                                </div>
                            </div>
                        </div>
                    </section>
    <!-- DEPARTMENT ALERT BAR: END -->
        }
    }
    

    The values are not included in this document type, but rather the ancestor document type.

    I have two questions:

    Is the body of my code OK since this document type doesn't have the documentAlertMessage/Title values, and,

    How do I word my if statement,

    @if (Model.HasValue("departmentAlertMessage"))
    

    to go back recursively.

  • Huw Reddick 1810 posts 6223 karma points MVP c-trib
    6 days ago
    Huw Reddick
    0

    something like

    @if (Model.AncestorOrSelf().HasValue("departmentAlertMessage"))
    
  • Lee M. Childress 14 posts 94 karma points
    6 days ago
    Lee M. Childress
    0

    Huw, I don't know how I would have made the transition to Umbraco without your help. You don't realize how appreciated you are. For whatever reason what you provided as a sample didn't work, but for anyone else with the same issue, this is what I did (which is obviously what I should have used in the first place)

    @if (Model.HasValue("departmentAlertMessage", fallback: Fallback.ToAncestors))
    {
    }
    
  • Huw Reddick 1810 posts 6223 karma points MVP c-trib
    6 days ago
    Huw Reddick
    0

    Ah yes, forgot about the fallback route. Glad you found the answer. Thanks for your kind words 😊

Please Sign in or register to post replies

Write your reply to:

Draft