Thanks for that. The first one you gave looks like the right one. All repositories have the same Document Type I tried putting it in and I got this error:
"Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type".
I think my problem is using that code in a foreach:
foreach (var item in Model.AncestorOrSelf(1).DescendantsOrSelf().Items.Where(x=>x.Name == collect)) { ** do something for each recipe's properties: (item.Name, item.Image, item.description) in the chosen repository ** }
Do I need to collect the recipes into an array and then use that in the foreach for this to work?
Brilliant! Thanks Ali, that worked a charm. I had to remove AncestorsOrSelf(1) because I moved the repositories into a parent repository, but works great!
Collect items from variable repository name.
I've tried so many different ways of getting items that have a repository name of a variable via a querystring.
Here is my content tree:
Content
- > Homepage
- > Recipe Repository (named rep1)
- > Recipe Item
- > Recipe Item
- > Recipe Item
- > Recipe Item
- > Recipe Repository (named rep2)
- > Recipe Item
- > Recipe Item
- > Recipe Repository (named rep3)
- > Recipe Item
- > Recipe Item
- > Recipe Repository (named rep4)
- > Recipe Item
- > Recipe Item
string collect = querystring that will match one of five repositories (equalling either rep1, rep2, rep3 or rep4)
To get items matching querystring repository, I've tried:
Model.AncestorOrSelf().Descendants.Where("NodeTypeAlias == "+@collect).Children;
Model.AncestorsOrSelf().RecipeRepositories(@collect).RecipeItems;
What is the correct way of setting this out? I'm going crazy over this and I know it will be something incredibly obvious. Thanks in advance.
try this
assuming that all the "Recipe Repository" have the same Document Type Alias.
if rep1/rep2 are the name of the node than use above but if they are different document type. then use below:
Hi Ali,
Thanks for that. The first one you gave looks like the right one. All repositories have the same Document Type I tried putting it in and I got this error:
"Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type".
I think my problem is using that code in a foreach:
foreach (var item in Model.AncestorOrSelf(1).DescendantsOrSelf().Items.Where(x=>x.Name == collect)) {
** do something for each recipe's properties: (item.Name, item.Image, item.description) in the chosen repository ** }
Do I need to collect the recipes into an array and then use that in the foreach for this to work?
Tried this from another recent post, but still no luck:
you dont need to do that actually. it should just work because the result of
would be IEnumerable
I would use CurrentModel to get proper intellisense in visual studio
update :
Brilliant! Thanks Ali, that worked a charm.
I had to remove AncestorsOrSelf(1) because I moved the repositories into a parent repository, but works great!
Thanks
is working on a reply...