Copied to clipboard

Flag this post as spam?

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


  • Jesper Ordrup 1019 posts 1528 karma points MVP
    May 25, 2014 @ 17:54
    Jesper Ordrup
    0

    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

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 25, 2014 @ 18:26
    Jeavon Leopold
    1

    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

  • Jesper Ordrup 1019 posts 1528 karma points MVP
    May 25, 2014 @ 18:51
    Jesper Ordrup
    0

    Thanks Jeavon. That's multiple ways. :-)

    Does it matter which I use? Ie why are there more than one?

    Best Jesper

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 25, 2014 @ 20:50
    Jeavon Leopold
    101

    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.

    Does that make sense?

    Jeavon

  • Jesper Ordrup 1019 posts 1528 karma points MVP
    May 25, 2014 @ 20:54
    Jesper Ordrup
    0

    If thats the only thing to it then I got it now. Thanks for following through :-)

    best
    Jesper 

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 25, 2014 @ 21:03
    Jeavon Leopold
    1

    Cool, another more complex example for you

    In dynamics you can do this (the "s" in "umbTextPages" makes it a collection)

    @foreach (var feature in homePage.umbTextPages.Where("featuredPage"))
    

    In typed you would do this

    @foreach (var feature in homePage.Children.Where(x => x.DocumentTypeAlias == "umbTextPage" && x.GetPropertyValue<bool>("featuredPage")))
    
  • Jesper Ordrup 1019 posts 1528 karma points MVP
    May 25, 2014 @ 23:00
    Jesper Ordrup
    0

    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 

Please Sign in or register to post replies

Write your reply to:

Draft