@Sebastiaan, that should work - it throws an error for me if there are no children of that type, but assuming you have that - I'm pretty sure it's working. I'll test it and reply shortly.
Yeah - tested this in a clean blog install and it works how I expect.
I'm guessing it's some sort of weird upgrade issue or just incorrect doc type alias
Jonas- null/0 nodes instead of error will be added for final - it's on my list, I noticed it this afternoon and didn't have time to fix it for the Beta
Okay i'll look into this and get it sorted for the final of 4.7 (non beta).. should add.. on the text pages (children) where it doesn't work, are there any children of type textpage?
Wait a minute, I just realized that this question might be very important. I have a structure like so:
Content Home Artikel 2011 02 MyArticle Article2
Do you mean that Model.Article will only work if articles are direct descendants of Model?
Looks like it as this works:
var root = Model;
while (root.Level > 1) { root = root.Parent; }
var all = root.ContentFolder.First().ContentFolder.First().ContentFolder.First().Article;
(there's also uQuery.GetNodesByType(docTypeAlias), which internally uses a cached compiled XPath expression to return a List<Node> collection of all matching nodes thoughout the tree)
The best way to get all of the nodes of a certain document type?
So how do I get all of the nodes of document type Article using the new query language?
Hi Sebastiaan
Two ways:
@Model.nodeTypeAlias[es]
e.g.: @Model.newsItem or @Model.newsItems (both should work)
or
the more advanced XPath helper:
@Model.XPath("//newsItem"]
Gareth
With XPath:
var Articles = Model.XPath("//Article[@isDoc]");
Which is cool - but a DescendantsOrSelf should be a great addition to DynamicNode I think http://umbraco.codeplex.com/workitem/30070
/ Jonas
I'll put DescendantsOrSelf onto the list of features to add
Ah, didn't see your answer before I posted mine. Cheers Gareth, the new Razor rocks!
Good, I thought it should work like that but it doesn't (yet), when doing:
I get an exceptin: 'umbraco.MacroEngines.DynamicNode' does not contain a definition for 'Article'
The nodeTypeAlias is Article (I also tried Articles, pluralized, and lowercase "a" just to make sure).
And for the XPath I get the same error: 'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'XPath'
Maybe I missed something during the upgrade? Did all of the web.config changes, copied over the /bin /install /umbraco and /umbraco_client.
Ah yes, the XPath works without the children. But I was trying to avoid writing XSLT ;-)
@Sebastiaan, that should work - it throws an error for me if there are no children of that type, but assuming you have that - I'm pretty sure it's working.
I'll test it and reply shortly.
That's definitely working for me, though I haven't tested on the actual beta, just my dev version
The node type alias is case sensitive, but both plural and non plural work.
Can anyone confirm this doesn't work on the beta release?
I'll recheck in a clean install!
Did a clean install of the 4.7 beta release, installed the simple runway and trying to select all textpages:
@foreach(var t in Model.TextPage){
<p>@t.Id</p>
}
Error loading Razor Script
'umbraco.MacroEngines.DynamicNode' does not contain a definition for 'TextPage'
Tried all the variants with pluralization and lowercase as well, no dice unfortunately.
It works here (clean install with starterpack). But a null return instead of an error would be nice if the query returns 0 nodes.
For a (future) full node tree query withouth XPath - I guess this should be the usage with DescendantsOrSelf ?
The nodetype alias (in the starter pack) is umbTextpage so try Model.umbTextpage or Model.Parent.umbTextpage
Yeah - tested this in a clean blog install and it works how I expect.
I'm guessing it's some sort of weird upgrade issue or just incorrect doc type alias
Jonas- null/0 nodes instead of error will be added for final - it's on my list, I noticed it this afternoon and didn't have time to fix it for the Beta
@Jonas D'oh of course!! Works now in the clean install.
Going to compare some stuff then and report back, thanks.
I found it, it only works when you're on the homepage of the site, not on the textpages itself, I stuck it in the clean install's master page:
<umbraco:macro runat="server" language="razor">
@foreach(var t in Model.Parent.umbTextpage){
<p>@t.Id</p>
}
</umbraco:macro>
On the homepage this works fine, on the textpages itself I get:
Error loading Razor Script
'umbraco.MacroEngines.DynamicNode' does not contain a definition for 'umbTextPage'
this didn't help either:
Same error..
Okay i'll look into this and get it sorted for the final of 4.7 (non beta).. should add.. on the text pages (children) where it doesn't work, are there any children of type textpage?
Nope, it's just the normal tree:
= Simple website
== Installing modules
== Go further
== Getting started
Thanks Gareth! Keeping an eye on the codeplex commits ;-)
Wait a minute, I just realized that this question might be very important. I have a structure like so:
Content
Home
Artikel
2011
02
MyArticle
Article2
Do you mean that Model.Article will only work if articles are direct descendants of Model?
Looks like it as this works:
"All" now has all articles under Artikel/2011/02
Yes, as far as I understand, thats why we need DescendantsOrSelf.
Hi,
Yes that's correct - only direct descendants.
I'll be adding descendants & friends [decendantsandself, ancestorsorself) for the final 4.7.
I'm not sure when that's dropping though.
For now, you can do it the way shown above, or use the @Model.XPath("//xpath"") way
Hi Sebastiaan,
(there's also uQuery.GetNodesByType(docTypeAlias), which internally uses a cached compiled XPath expression to return a List<Node> collection of all matching nodes thoughout the tree)
Using it now Hendy, at least until the dynamic bits get a bit better :-)
is working on a reply...