Copied to clipboard

Flag this post as spam?

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


  • blackhawk 313 posts 1368 karma points
    Feb 15, 2018 @ 16:22
    blackhawk
    0

    How to reference a property from another page without depending on a Content Node ID, in Views (Razor)

    I'm on Umbraco 7.7.8. In my Views, I am working on a template that should reference a property from a specific content node.

    Can we do something like this in our templates...

     var othertemplateprop = Umbraco.TypedContentAtRoot().FirstOrDefault().Descendants("conHome").GetPropertyValue<IEnumerable<MeganavItem>>("topMenu");
    

    My thought process...

    1. Get to the root of the content tree.

    2. Descend down one level to find a content node that is referencing a document type by the name of conHome.

    3. Once I am connected, get a property value on it, called topMenu.

    Thanks for any thoughts

  • blackhawk 313 posts 1368 karma points
    Feb 15, 2018 @ 16:50
    blackhawk
    100

    The following is what I have working so far. But if you happen to know how I can capitlize on this further, than I'm all for it. For now this is working for me...

     var mconHome = Umbraco.TypedContentAtRoot().First().Descendants().Where(c => c.DocumentTypeAlias.Equals("conHome"));
    
                    foreach (var item in mconHome)
                    {
                        var mmeganav = item.GetPropertyValue<IEnumerable<MeganavItem>>("topMenu");
    
                        if (mmeganav != null)
                        {
                            <ul>
                                @foreach (var childitem in mmeganav)
                                {
                                    <li>
                                        <a href="@childitem.Url" target="@childitem.Target">@childitem.Title </a>
                                    </li>
                                }
                            </ul>
                        }
                    }
    
  • 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