Copied to clipboard

Flag this post as spam?

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


  • Fredrik Liljemark 52 posts 74 karma points
    Apr 13, 2012 @ 15:47
    Fredrik Liljemark
    0

    Retrieve templateid or templatename from Node.

    Hi,

    I have search for how to retrieve templateid or templatename from current node. But I cant seem to get it to work.

    I want to get all nodes that have a template assigned (for a navigation menu).

    But i cant seem to get it to work... i want to achieve something like below.
    I guess this is simple and that i have missed something essential...

    Ideas and examples anyone?

    var Nodes = root.Children.Where("Template != null");

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Apr 13, 2012 @ 15:53
    Tom Fulton
    0

    Hi,

    I believe Template is stored as an integer and nodes without templates have a value of 0.  So try this instead:

    var Nodes = root.Children.Where("Template > 0");

    HTH,
    Tom

  • Fredrik Liljemark 52 posts 74 karma points
    Apr 13, 2012 @ 16:12
    Fredrik Liljemark
    0

    Nope, that doesnt work either.

    I get no nodes on that one. =(

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Apr 13, 2012 @ 16:13
    Tom Fulton
    0

    Is this v4 or v5?  Seems to work for me on v4, are you sure your root variable is right?

    -Tom

  • Fredrik Liljemark 52 posts 74 karma points
    Apr 13, 2012 @ 16:15
    Fredrik Liljemark
    0

    V5, sorry... 

        root = DynamicModel;
        var barnNoder = root.Children.Where("Template > 0");
    I managed to solve this with this code, maybe not that fancy... but it works.
    But im hoping for a better way in the future. =) 
            root = DynamicModel;
            var barnNoder = root.Children;
            foreach (var item in barnNoder)
            {
                string templatenamn = item.Template.ToString();
                if (templatenamn != "")
    
  • Tom Fulton 2030 posts 4998 karma points c-trib
    Apr 13, 2012 @ 17:20
    Tom Fulton
    0

    Hi,

    Yep, was just going to suggest that as a workaround :)

    I think there might be a bug.  I would think this would work but it returns nothing:

    var nodes = DynamicModel.Children.Where("Template == @0", "Textpage");

    I did some testing and couldn't get it working and also found some other bugs, it seems when you do a .Where you then lose the .Template on your nodes.  Going to test further and report an issue.

    -Tom

  • Fredrik Liljemark 52 posts 74 karma points
    Apr 13, 2012 @ 17:23
    Fredrik Liljemark
    0

    Ok, thanks alot.

    I have quite some time on this one, I thought I was missing something obvious.  
     

Please Sign in or register to post replies

Write your reply to:

Draft