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 16 posts 96 karma points
    Jun 06, 2024 @ 13:51
    Lee M. Childress
    0

    Recursive Issue

    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 1875 posts 6421 karma points MVP 2x c-trib
    Jun 07, 2024 @ 10:03
    Huw Reddick
    0

    something like

    @if (Model.AncestorOrSelf().HasValue("departmentAlertMessage"))
    
  • Lee M. Childress 16 posts 96 karma points
    Jun 07, 2024 @ 12:58
    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 1875 posts 6421 karma points MVP 2x c-trib
    Jun 07, 2024 @ 13:11
    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