Copied to clipboard

Flag this post as spam?

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


  • Chris Whittington 6 posts 26 karma points
    Oct 22, 2013 @ 12:20
    Chris Whittington
    0

    Node usage question

    I'm after some best practice advice.

    Within our organisation we are keen to be using the latest API methods (nothing obsolete or scheduled to be removed with V7).

    With that in mind following discussions with members of the umbraco HQ team we have started to factor out the use of the uQuery component.

    My question is this: uQuery made use of the Node classes within umbraco.NodeFactory. Is it favourable to use these classes or stick to using IPublishedContent?

    Node has methods for easy Id retrieval whereas IPublishedContent requires us to implement our own logic for locating valid documents within umbraco.config.

    Any advice would be really appreciated.

    Chris Whittington

  • Lars-Erik Aabech 349 posts 1100 karma points MVP 7x c-trib
    Oct 23, 2013 @ 11:36
    Lars-Erik Aabech
    0

    Not quite sure I understand the question, but I'd recommend going for IPublishedContent.
    It's all "just cached XML" behind the scenes anyway, and the media is in a Lucene index.
    To query it you just use the Enumerable/Queryable extensions.
    For instance content.Children().Where(c => c.Alias == "someDocumentType") or even use a core extension: content.Children().Where(c => c.IsDocumentType("someDocumentType").

    At the risk of doing too much blatant self-promotion, you should also have a look at the typed model stuff I'm (we're) doing:
    https://github.com/lars-erik/Umbraco.CodeGen / http://our.umbraco.org//projects/developer-tools/umbraco-codegen
    With it, you can start doing content.Children().OfType<Article>() or content.Descendants.OfType<Article>(), add .Where(m => m.StronglyTypedProperty == "whatever") etc.
    (Won't be 100% nice until a future 6.x release)

  • Chris Whittington 6 posts 26 karma points
    Oct 23, 2013 @ 14:58
    Chris Whittington
    0

    Thanks for the reply Lars. I'll have a look into your link, from what you say your new code would be very useful (can't wait for you to release it ;))

    IPublishedContent is the way to go as you say, its unfortunate that there are no GetById / GetRootNode methods associated with it but I've just noticed that the UmbracoHelper class gives us access to all the goodness that we require e.g.

    UmbracoHelper.TypedContent(1123); // returns IPublishedContent
    
  • Lars-Erik Aabech 349 posts 1100 karma points MVP 7x c-trib
    Oct 23, 2013 @ 15:04
    Lars-Erik Aabech
    0

    You're right on track. :)

    IPublishedContent also have a couple of nice extensions to navigate upwards.

    content.AncestorOrSelf("rootAlias") < should be your root. (or AncestorOrSelf(<level>))

    Full list of extensions here:
    http://our.umbraco.org/documentation/Reference/Mvc/querying

    Regarding the codegen plugin. It's finished and released with regards to generating and parsing typed models, but it won't be as easy to use (without some plumbing) until the core team has done a couple of tweaks in the core.

    L-E

  • Lars-Erik Aabech 349 posts 1100 karma points MVP 7x c-trib
    Oct 23, 2013 @ 15:06
    Lars-Erik Aabech
    0

    Umm.. Forgot to mention, if you're using MVC, all your views have UmbracoHelper as a property called Umbraco.
    So in your views, you can just do @Umbraco.TypedContent(id).Url etc.

Please Sign in or register to post replies

Write your reply to:

Draft