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){
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 )
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 } }
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>
}
}
Hi Doogie,
What if you do something like this:
Hope this helps,
/Dennis
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
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
Hope this helps,
/Dennis
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. :)
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
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>
}
}
is working on a reply...