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.
Thanks much! Just to confirm do I need to add, @using umbraco.MacroEngines namespace or is @inherits Umbraco.Web.Macros.PartialViewMacroPage good enough?
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.
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.
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
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!
Hi Stan,
@Library.NodeById(1234)
has been replaced by@Umbraco.Content(1234)
in a Partial View MacroJeavon
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)
?
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
Thanks much! Just to confirm do I need to add, @using umbraco.MacroEngines namespace or is @inherits Umbraco.Web.Macros.PartialViewMacroPage good enough?
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.
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.
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
is working on a reply...