Copied to clipboard

Flag this post as spam?

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


  • Akil 2 posts 72 karma points
    Nov 22, 2022 @ 19:31
    Akil
    0

    Add Logo In the Middle Of a Dynamic Menu

    Hi,

    Is there a way I can add a logo in the middle of the site menu like below using a dynamic razor file?

    <ul>
    <li>Home</li>
    <li>Blog</li>
    <li>About</li>
        <li>LOGO HERE</li>  <------
    <li>Services</li>
    <li>Explore</li>
    <li>Contact</li>
    </ul>
    

    My macro code is

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{ 
    
        var level = String.IsNullOrEmpty(Parameter.Level) ? 1 : int.Parse(Parameter.Level); 
    
        var parent = @Model.AncestorOrSelf(level);
        if (parent != null) {
            <ul class="menu vertical medium-horizontal">
                <li><a href="/">Home</a></li>
            @foreach (var item in parent.Children.Where("Visible")) {
                var active = Array.IndexOf(Model.Path.Split(','), item.Id.ToString()) >= 0 ? " class=\"active\"" : "";
                <li@Html.Raw(active)>
                    <a href="@item.Url">@item.Name</a>
                </li>
                }
            </ul>
        }
    }
    

    Thank you.

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 9x admin c-trib
    Nov 23, 2022 @ 15:11
    Alex Skrypnyk
    0

    Hi

    Try to use indexOf method, something like this:

            @foreach (var item in parent.Children.Where("Visible"))
            {
                if (parent.Children.Where("Visible").IndexOf(item) == 3)
                {
                    <li>LOGO HERE</li>  
                }
    
                    var active = Array.IndexOf(Model.Path.Split(','), item.Id.ToString()) >= 0 ? " class=\"active\"" : "";
                    <li @Html.Raw(active)>
                        <a href="@item.Url">@item.Name</a>
                    </li>
    
            }
    
  • Akil 2 posts 72 karma points
    Nov 24, 2022 @ 05:56
    Akil
    0

    Hi Alex,

    Thank you for your quick answer. I tried that but it didn't work. Gave me a macro error.

    I think I need to define what IndexOf(item) == 3 is.

  • 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