Copied to clipboard

Flag this post as spam?

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


  • Ayo Adesina 445 posts 1059 karma points
    Sep 15, 2014 @ 11:44
    Ayo Adesina
    0

    Umbraco 6 - Basic Content node navigation.

    Hey guys I have been away for a while, the last time I was using umbraco I was using version 4.

    I am currently using version 6 and can't find the methods in the API to get particular nodes and query there properties. According to the back office of umbraco I am using - Umbraco v6.2.1

    After a bit of googling and reading I have found that uQuery has been put in to the umbraco core and this is the object I need. However, even though I have this using statement.

    using umbraco;

    I can't access uqery, its not in that name space, I have also tried

    using umbraco.NodeFactory

    but the NodeFactory is also not in the Umbraco name space.

    What I have found is:

    ContentService

    so if I do something like this:

    var childnodes = contentService.GetChildren(1503);

    how do I count the number of nodes? ie

    childnodes.count is not valid

    Also how do I loop through the items and see what values are set for a given property?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Sep 15, 2014 @ 12:06
    Jeroen Breuer
    0

    Hello,

    You should use the Umbraco helper for this. With that it's possible to do this: 

    var node = Umbraco.TypedContent(id);

    More info: http://our.umbraco.org/documentation/Reference/Mvc/querying

    Jeroen

  • Ayo Adesina 445 posts 1059 karma points
    Sep 15, 2014 @ 12:27
    Ayo Adesina
    0

    Thanks for your quick reply Jeroen

    When I do Umbraco. the only option I get is CORE.. so Umbraco.Core

    so there is no Umbraco.TypedContent or Umbraco.Core.TypedContent

    Just checked and I am using a separate class library project I have a reference to Umbraco.Core but not to Umbraco,

    Do I need to add an assembly reference to this? In my CMS project (ie the umbraco website project) there is a Umbraco.dll file with file version 1.0.5261.29001

    Do I need to reference this?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Sep 15, 2014 @ 12:59
    Jeroen Breuer
    0

    Hello,

    You can create your own helper like this:

    using Umbraco.Web;

    protected static UmbracoHelper Umbraco { get { return new UmbracoHelper(UmbracoContext.Current); } }

    It might be good to add the Umbraco.Core dll and add that namespace for a lot of good extension methods.

    Jeroen

  • Ayo Adesina 445 posts 1059 karma points
    Sep 15, 2014 @ 13:00
    Ayo Adesina
    0

    I have found the TypedContent method now... but I can only get the nodes by ID.. I want to get it by type and name... if I can so that I don't have to worry about someone deleting/recreating the node with a different ID

    Any ideas?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Sep 15, 2014 @ 13:18
    Jeroen Breuer
    0

    It might be easier to just store the id in the web.config as an app setting. If someone deletes/recreate it you just have to update the id in the app setting. Another option is to select the node with a content picker on the top node and get that id. Finally if you want to find a specific node you could get the root node and query all Descendants with a where statement in which you search for the name and type.

    Jeroen

Please Sign in or register to post replies

Write your reply to:

Draft