Copied to clipboard

Flag this post as spam?

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


  • Stan 13 posts 53 karma points
    Mar 12, 2014 @ 16:27
    Stan
    0

    NodeById in Partial Views Macros

    Hello,

    Hopefully this should be easy ;-) . I need to reference/access a node not in the current content tree and its properties. I know there is NodeById method, but i can seem to get it to work particually in a partial view macro.

    How do I use it? what addionally namespace do i need to include? Is there another method i should be using in this context?

    Thanks again. So far everyone in this commuity has been amazing.

    Cheers!

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Mar 12, 2014 @ 16:30
    Jeavon Leopold
    0

    Hi Stan,

    @Library.NodeById(1234) has been replaced by @Umbraco.Content(1234) in a Partial View Macro

    Jeavon

  • Stan 13 posts 53 karma points
    Mar 12, 2014 @ 16:56
    Stan
    0

    Wow! cool. Didn't see that anywhere. Is there someplace or cheetsheet that list methods available (or most popular) for partial views macros?

    So basically i just use

    var node = @Library.NodeById(1234)

    ?

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Mar 12, 2014 @ 17:00
    Jeavon Leopold
    0

    Well, you need to use var node = Umbraco.Content(1234);

    Here is a link to the cheatsheet you need, this is the dynamic version. There is also a strongly typed version of the cheatsheet here

  • Stan 13 posts 53 karma points
    Mar 12, 2014 @ 17:23
    Stan
    0

    Thanks much! Just to confirm do I need to add, @using umbraco.MacroEngines namespace or is @inherits Umbraco.Web.Macros.PartialViewMacroPage good enough?

     

     

     

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Mar 12, 2014 @ 18:17
    Jeavon Leopold
    0

    Just the inherits. When using a partial view macro, there shouldn't ever be a mention of DynamicNode or umbraco.MacroEngines, this is for legacy support only.

  • Eric Schrepel 161 posts 226 karma points
    Apr 10, 2014 @ 19:59
    Eric Schrepel
    0

    Is Umbraco.Content the preferred (and fast) method for reading node content now? This stackoverflow thread from 2012 suggested to not use Umbraco.Content, but maybe that's changing now? If we shouldn't be using the Umbraco.Content approach, I'm having trouble figuring out how to read nodes in Partial Views otherwise.

    We're in the process of converting most of our 6.1.6 macros into just Partial Views (and a few Partial View macros), and have been switching from Model.NodeById(nodenumber) to Umbraco.Content(nodenumber), which seems to be working well, though we haven't done speed tests to see if there are any issues.

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Apr 10, 2014 @ 20:05
    Jeavon Leopold
    0

    Hi Eric,

    Yes UmbracoHelper accessed through Umbraco.Content or Umbraco.TypedContent are the main methods of getting published node content when using any sort of MVC templating with Umbraco. That old SO post is actually talking about the now legacy management API which is quite different anyway.

    Documentation on UmbracoHelper is here and general MVC templating documentation is here

    Jeavon

Please Sign in or register to post replies

Write your reply to:

Draft