var umbracoHelper =newUmbracoHelper(UmbracoContext.Current);var rootNode = umbracoHelper.TypedContentSingleAtXPath("//root"));
..results in the exception "ContentTypeService failed to find a content type with alias "root"".
Any ideas? Are we supposed to still use the Node(-1) method for this? I thought "Node" is a thing from the past.
Are we supposed to access the root node at all in Umbraco 6/7?
On an different but related note: I think it would be a good idea to agree on one name for a Node/Item/Page/Content and work towards consistency in the API on this point, because it is becoming hard to distuingish between all the terms that are used for what was called a Node in Umbraco 4 and is now called Content in the Content API, but a CurrentPage when we are in a Controller or Razor. This is especially confusing for beginners...
I think the idea is more that you access the content nodes at the root (maybe more than one) rather than a single root node per se. But from that you can get the first one.
I think this is indeed the case and that Umbraco has seen an undocumented (or I didn't find it yet) paradigm shift in how the node tree is accessed.
In pre-Umbraco 6 we would often get the root node through the node API by using Node(-1)
I have tried every possible way of finding the root node in U6/7 but haven't been able to get hold of it.
I also tried this:
var publishedContent = _currentNode.Ancestor(1).Ancestor();
but this results in null.
I think we are now supposed to use the TypedContentAtRoot nodes or base our searches on the current node. This does make it harder to search the entire tree which ius exactly want I want to implement in a separate class library I am building for retrieving content from the Umbraco tree.
I would start getting root node using typed content and Xpath expressions. Its just messy imo. If you need to get Nodes on the same level as Level 1 you can do i think its:
@Kevin: I see what you mean, but I am creating a library that I want to work with any tree, so I don't want to impose a particular way of working for my lib to work :)
I found a strategy where the client programmer can decide whether he/she wants to start search the current branch (ancestors and descendants of the current node), just the descendants of the current node or the entire tree. Works for me :)
private IEnumerable<IPublishedContent> GetSearchStartNodes(SearchBehaviour behaviour) { var searchStartNodes = new List<IPublishedContent>(); if (behaviour.Equals(SearchBehaviour.EntireTree)) { searchStartNodes = _helper.TypedContentAtRoot().ToList(); } else if(behaviour.Equals(SearchBehaviour.CurrentBranch)) { searchStartNodes.Add(_currentNode.AncestorOrSelf(1)); } else if (behaviour.Equals(SearchBehaviour.DescendantsOrSelf)) { searchStartNodes.Add(_currentNode); } else { throw new UmbracoDataException(string.Format("Behaviour called '{0}' is not recognized", behaviour)); }
Git is trying to commit files in the App_data folder that are not included in the .gitignore that you provided. Are we able to ignore these files, get rid of them somehow, or should we be committing them with our changes?
This was a part of my solution to getting the correct node for a multilanguage site in Umbraco 7
var pathList = Node.GetCurrent().Path.Split(',');
int domainNodeId = -1;
if (int.TryParse(pathList[1], out domainNodeId))
domainNode = new Node(domainNodeId);
How to get the root node in Umbraco 6/7
Hey, I am trying to get the root node in Umbraco 7 (case should be the same for Umbraco 6).
The suggestions I found here don't work.
http://stackoverflow.com/questions/11940537/umbraco-finding-root-node-in-c-sharp
UmbracoHelper.TypedContent(-1) returns null
Umbraco.Content(-1) returns an empty 'dynamic'
..results in the exception "ContentTypeService failed to find a content type with alias "root"".
Any ideas? Are we supposed to still use the Node(-1) method for this? I thought "Node" is a thing from the past.
Are we supposed to access the root node at all in Umbraco 6/7?
On an different but related note: I think it would be a good idea to agree on one name for a Node/Item/Page/Content and work towards consistency in the API on this point, because it is becoming hard to distuingish between all the terms that are used for what was called a Node in Umbraco 4 and is now called Content in the Content API, but a CurrentPage when we are in a Controller or Razor. This is especially confusing for beginners...
You can use this:
I think the idea is more that you access the content nodes at the root (maybe more than one) rather than a single root node per se. But from that you can get the first one.
Andy
Hi Andy,
I think this is indeed the case and that Umbraco has seen an undocumented (or I didn't find it yet) paradigm shift in how the node tree is accessed.
In pre-Umbraco 6 we would often get the root node through the node API by using Node(-1)
I have tried every possible way of finding the root node in U6/7 but haven't been able to get hold of it.
I also tried this:
but this results in null.
I think we are now supposed to use the TypedContentAtRoot nodes or base our searches on the current node. This does make it harder to search the entire tree which ius exactly want I want to implement in a separate class library I am building for retrieving content from the Umbraco tree.
Comment author was deleted
FWIW, Umbraco best practice is to build a site with a single root node.
i.e.
Content
- Home
-- Node
-- Node
as opposed to
Content
- Node
- Node
- Node
If you have multiple sites on one install, it should look like this:
- Sites
-- Home 1
--- Node
-- Home 2
--- Node
Therefore if you do an Ancestor(1), you'll get the the top level node which you can then search.
I would start getting root node using typed content and Xpath expressions. Its just messy imo. If you need to get Nodes on the same level as Level 1 you can do i think its:
siblings > where doc type = your nodes doc type.
Hope this helps. Charlie :)
@Kevin: I see what you mean, but I am creating a library that I want to work with any tree, so I don't want to impose a particular way of working for my lib to work :)
I found a strategy where the client programmer can decide whether he/she wants to start search the current branch (ancestors and descendants of the current node), just the descendants of the current node or the entire tree. Works for me :)
Comment author was deleted
Great!
Get nodes at root level in Umbraco 7:
Credit to Andy Butland.
My solution:
Fyin.com: Chicago Umbraco Developers
Hi,
Git is trying to commit files in the App_data folder that are not included in the .gitignore that you provided. Are we able to ignore these files, get rid of them somehow, or should we be committing them with our changes?
This was a part of my solution to getting the correct node for a multilanguage site in Umbraco 7
is working on a reply...