Copied to clipboard

Flag this post as spam?

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


  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Feb 23, 2011 @ 09:34
    Sebastiaan Janssen
    2

    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?

  • Gareth Evans 143 posts 335 karma points c-trib
    Feb 23, 2011 @ 10:07
    Gareth Evans
    0

    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

  • Jonas Eriksson 930 posts 1825 karma points
    Feb 23, 2011 @ 10:13
    Jonas Eriksson
    0

    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

  • Gareth Evans 143 posts 335 karma points c-trib
    Feb 23, 2011 @ 10:15
    Gareth Evans
    0

    I'll put DescendantsOrSelf onto the list of features to add

  • Jonas Eriksson 930 posts 1825 karma points
    Feb 23, 2011 @ 10:19
    Jonas Eriksson
    0

    Ah, didn't see your answer before I posted mine. Cheers Gareth, the new Razor rocks!

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Feb 23, 2011 @ 10:23
    Sebastiaan Janssen
    0

    Good, I thought it should work like that but it doesn't (yet), when doing:

    @foreach (var art in Model.Article) {
        <p>@art.Id</p>
    }

    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.

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Feb 23, 2011 @ 10:25
    Sebastiaan Janssen
    0

    Ah yes, the XPath works without the children. But I was trying to avoid writing XSLT ;-)

  • Gareth Evans 143 posts 335 karma points c-trib
    Feb 23, 2011 @ 10:29
    Gareth Evans
    0

    @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.

  • Gareth Evans 143 posts 335 karma points c-trib
    Feb 23, 2011 @ 10:38
    Gareth Evans
    0

    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?

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Feb 23, 2011 @ 10:43
    Sebastiaan Janssen
    0

    I'll recheck in a clean install!

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Feb 23, 2011 @ 10:51
    Sebastiaan Janssen
    0

    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.

  • Jonas Eriksson 930 posts 1825 karma points
    Feb 23, 2011 @ 10:57
    Jonas Eriksson
    0

    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 ?

    var nodeList = Model.AncestorOrSelf().DescendantsOrSelf.Where("NodeTypeAlias=\"umbTextpage\"");
    foreach (var n in nodeList)
    {
    @n.Name

    }

     

  • Jonas Eriksson 930 posts 1825 karma points
    Feb 23, 2011 @ 10:59
    Jonas Eriksson
    0

    The nodetype alias (in the starter pack) is umbTextpage so try Model.umbTextpage or Model.Parent.umbTextpage

  • Gareth Evans 143 posts 335 karma points c-trib
    Feb 23, 2011 @ 11:05
    Gareth Evans
    0

    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

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Feb 23, 2011 @ 11:13
    Sebastiaan Janssen
    0

    @Jonas D'oh of course!! Works now in the clean install. 

    Going to compare some stuff then and report back, thanks.

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Feb 23, 2011 @ 12:08
    Sebastiaan Janssen
    0

    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:

                
                  
    @{ 
                    var root = Model;
                    while (root.Level > 1) { root = root.Parent; } 
                    var textPages = root.umbTextPage;
                  }
                  
                  @foreach(var t in textPages){
                    <p>@t.Idp>
                  }
               

    Same error..

  • Gareth Evans 143 posts 335 karma points c-trib
    Feb 23, 2011 @ 12:30
    Gareth Evans
    0

    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?

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Feb 23, 2011 @ 13:22
    Sebastiaan Janssen
    0

    Nope, it's just the normal tree:

    = Simple website
    == Installing modules
    == Go further
    == Getting started

    Thanks Gareth! Keeping an eye on the codeplex commits ;-)

     

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Feb 23, 2011 @ 16:55
    Sebastiaan Janssen
    0

    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;

    "All" now has all articles under Artikel/2011/02

  • Jonas Eriksson 930 posts 1825 karma points
    Feb 23, 2011 @ 17:14
    Jonas Eriksson
    0

    Yes, as far as I understand, thats why we need DescendantsOrSelf.

  • Gareth Evans 143 posts 335 karma points c-trib
    Feb 23, 2011 @ 22:34
    Gareth Evans
    0

    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

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Feb 24, 2011 @ 12:33
    Hendy Racher
    2

    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)

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Feb 24, 2011 @ 16:05
    Sebastiaan Janssen
    0

    Using it now Hendy, at least until the dynamic bits get a bit better :-)

Please Sign in or register to post replies

Write your reply to:

Draft