It seems there are multiple ways to get to published data? Which is the preferred? Is it different what you need to do if you're on a umbraco template (view) or macro?
With Umbraco 7 the recommended method is to use IPublishedContent, this can be dynamic (CurrentPage) or typed (Model.Content). Anything else is legacy.
There are cheatsheets a for both dynamic and typed here and IPublishedContent is documented here
It's a preference really, dynamic is more concise but typed gives you intellisense in Visual Studio.
Classic example:
CurrentPage.myProperty vs Model.Content.GetPropertyValue("myProperty")
If you use Visual Studio then typed makes sense, if you use the Umbraco UI template editor or another authoring tool then dynamic probably makes more sense.
I must admit that the picture is getting clearer :)
I must have seen this page 100 times - http://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets - and early I wrongly came to the conclusion that there were 3 downloads = 3 ways to access (razor, dynamic and strong). But today when I re-read the page it states two cheatsheets and one of the downloads just contains both.
Razor - working with property data?
It seems there are multiple ways to get to published data? Which is the preferred? Is it different what you need to do if you're on a umbraco template (view) or macro?
Documentation links to a cheatsheat from 4.7
http://our.umbraco.org/documentation/Cheatsheets/
Still the preferred?
best
Jesper
Hi Jesper,
With Umbraco 7 the recommended method is to use IPublishedContent, this can be dynamic (CurrentPage) or typed (Model.Content). Anything else is legacy.
There are cheatsheets a for both dynamic and typed here and IPublishedContent is documented here
Jeavon
Thanks Jeavon. That's multiple ways. :-)
Does it matter which I use? Ie why are there more than one?
Best Jesper
It's a preference really, dynamic is more concise but typed gives you intellisense in Visual Studio.
Classic example:
CurrentPage.myProperty
vsModel.Content.GetPropertyValue("myProperty")
If you use Visual Studio then typed makes sense, if you use the Umbraco UI template editor or another authoring tool then dynamic probably makes more sense.
Does that make sense?
Jeavon
If thats the only thing to it then I got it now. Thanks for following through :-)
best
Jesper
Cool, another more complex example for you
In dynamics you can do this (the "s" in "umbTextPages" makes it a collection)
In typed you would do this
Thanks Jeavon,
I must admit that the picture is getting clearer :)
I must have seen this page 100 times - http://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets - and early I wrongly came to the conclusion that there were 3 downloads = 3 ways to access (razor, dynamic and strong). But today when I re-read the page it states two cheatsheets and one of the downloads just contains both.
Sometimes "paragraph" reading doesnt work :)
best
Jesper
is working on a reply...