Copied to clipboard

Flag this post as spam?

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


  • Doogie Talons 183 posts 318 karma points
    Sep 30, 2014 @ 21:26
    Doogie Talons
    0

    Having trouble with calling pages based on the contents of its tree picker...

    Hi I have been having trouble with various scripts to achieve something I thought would be simple.

    It would be easier to show you clever chaps the code I have already done, rather than explain the problem. I hope one of you can help. Obviously the second foreach contains gibberish but it should show you what I am getting at.

    Regards, Doogie.

     

    categoryPicker is a property that contains the selections from a tree picker... or empty.

    @{   var caseNode = Library.NodeById(1184); 

         var catNode = Library.NodeById(2108);  }

     

    @foreach (var category in catNode.Children.Where("visible"))

    {

    <h2>@category.Name | @category.Id</h2>

    foreach(var casestudy in caseNode.Children.Where("projectCategory" contains category.Id){

    <p>@casestudy.Name</p>

    }

    }

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Sep 30, 2014 @ 22:24
    Dennis Aaen
    0

    Hi Doogie,

    What if you do something like this:

    @{   
        var caseNode = Library.NodeById(1184);
        var catNode = Library.NodeById(2108);
       
        foreach(var category  in catNode.Children.Where("visible")){  
            <h2>@category.Name | @category.Id</h2>
                foreach(var casestudy in caseNode.Children){
                    <p>@casestudy.Name</p>
                }
        }
    }     

    Hope this helps,

    /Dennis

  • Doogie Talons 183 posts 318 karma points
    Sep 30, 2014 @ 22:36
    Doogie Talons
    0

    Sorry Dennis, that just returns the entire list of case studies. 

    Each casestudy has a multinode tree picker with the contents of catNode

    What I wanted to do was itterate through the categories of catNode, then itterate through all the case studies that have the category id in the projectCategory property (which is the multinode tree picker that has the category selection in )

     

    Strangley...

    foreach(var casestudy in caseNode.Children.Where("projectCategory.Contains(\"2109\")" ))    

     

    Works ( But the 2109 is one possible result of catid in the top example )  

     

    Doogie

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Sep 30, 2014 @ 22:55
    Dennis Aaen
    0

    Hi Doogie,

    Ah okay, Did you see the documentation for the Multi-Node-Tree-Picker. There are also an example on how to configure it and get data from it using the DynamicNode razor: http://our.umbraco.org/documentation/using-umbraco/backoffice-overview/property-editors/built-in-property-editors/Multi-Node-Tree-Picker

    Here is an example from one of my project where I use the Multi-Node-Tree-Picker. In this example my propertyAlias of Multi-Node-Tree-Picker is contentElementMain. And I get the elements that are picked on the page that you are view in the browser there for Model.contentElementMain

    @inherits umbraco.MacroEngines.DynamicNodeContext                                                    

    @if (Model.HasValue("contentElementMain")){
    foreach (var item in Model.contentElementMain){
                var node = Library.NodeById(item.InnerText);
                @node.Name
    }
    }

    Hope this helps,

    /Dennis

  • Doogie Talons 183 posts 318 karma points
    Sep 30, 2014 @ 23:29
    Doogie Talons
    0

    Aye read, and reread that page :) this seems a particular type of cruelty I am just missing something.

    Not helped by my inability to make the issue clear...

    I will try and simplyfy it...

    This works.

    foreach(var casestudy in caseNode.Children.Where("projectCategory.Contains(\"2109\")" ))    

    but instead of the number 2109 i want to replace 2109 with a variable like @catid which would hold the number 2109 in that itteration.

    This for example fails

    var catid = "2109" ;

    foreach(var casestudy in caseNode.Children.Where("projectCategory.Contains(catid)" ))    

    So I am a bit stumped. :)

     

     

     

     

     

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Sep 30, 2014 @ 23:52
    Dennis Aaen
    100

    Hi Doogie,

    What if you are doing something like this:

    var catid = "2109";

    foreach(var casestudy in caseNode.Children.Where("projectCategory.Contains(@0)",catid))   

    Hope this helps,

    /Dennis

     

  • Doogie Talons 183 posts 318 karma points
    Oct 01, 2014 @ 00:04
    Doogie Talons
    0

    Perfect.... this is the final script for anyone watching. Don't quite understand the use of the (@0) bit, but it works fine. Thanks very much Denis.

    @{  

    var caseNode = Library.NodeById(1184);
    var catNode = Library.NodeById(2108);  }

    @foreach (var category in catNode.Children.Where("visible"))

    {

    <h2>@category.Name</h2>

    var catid = category.Id.ToString();

    foreach(var casestudy in caseNode.Children.Where("projectCategory.Contains(@0)",catid))   {

    <p>@casestudy.Name</p>

    }

    }

Please Sign in or register to post replies

Write your reply to:

Draft