Copied to clipboard

Flag this post as spam?

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


  • strawberrylatte 32 posts 100 karma points
    Mar 03, 2021 @ 00:35
    strawberrylatte
    0

    Check if IPublishedContent has a template or not

    I am new at Umbraco and I want to find out if my IPublishedContent has a template or not, if yes, the template will be displayed and if not, the link will be set as #. This is the bit of code that I wanted to edit.

    @{
                                        var root = Model.Value<IPublishedContent>("sidebarRootNode", fallback: Fallback.ToAncestors);
    
                                        if (root != null)
                                        {
                                            foreach (var child in root.Children)
                                            {
                                                <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-5818 @(Model.Url == child.Url ? "current-menu-item" : null)" style="display: flex; justify-content: space-between">
                                                    <a href="@child.Url">@child.Name</a>
                                                    @if (child.Children.Any() && !child.IsDocumentType("people"))
                                                    {
                                                        <button href="#" onclick="toggleChildMenu('[email protected]', this)" style="cursor: pointer; background: none; border: none; padding: 0 1rem; font-size: 1rem; color: rgb(140, 140, 140)">
                                                            <i class="fa fa-chevron-down" aria-hidden="true"></i>
                                                        </button>
                                                    }
                                                </li>
                                                if (child.Children.Any() && !child.IsDocumentType("people")) // don't show child nodes of people
                                                {
                                                    <li id="[email protected]" style="border: none; display: none;">
                                                        <ul style="margin-left: 1rem; margin-bottom: 0;" class="gdlr-core-custom-menu-widget gdlr-core-menu-style-list">
                                                            @foreach (var child2 in child.Children)
                                                            {
                                                                <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-5818 @(Model.Url == child2.Url ? "current-menu-item" : null)">
                                                                    <a href="@child2.Url">@child2.Name</a>
                                                                </li>
                                                            }
                                                        </ul>
                                                    </li>
                                                }
                                            }
                                        }
                                    }
    
  • Liam Dilley 98 posts 245 karma points
    Mar 03, 2021 @ 02:53
    Liam Dilley
    0

    You can get a template Alias by using:

    var templateAlias = Model.GetTemplateAlias();
    

    You can check on that or if is not returning one.

Please Sign in or register to post replies

Write your reply to:

Draft