Hello
The way I store the nodes in my magazine is currently by years (2012 / 2013 / 2014)
Now when I display the nodes (posts) I rub a loop on each year.
What I want to do now is to add months - then when I display the posts (nodes) list I'll have to "scan" each month - like when I'll run on the years node I'll have to go inside every month - is there any technique to do it? I thought maybe using recursion?
I made a small image to try illustrate what I try to achieve: at the right is what I have now, at the left is what I try to achieve
How do i get content from the bottom of the structure(a magazine item) given i have Year, Month, Day structure.
What you need i think is LINQ to get the descendants of each year folder where your document type alias == the document type alias you have given the magazine item).
(Because I used the code from this great tutorial :) , and in order to keep this tread clean and w/o lot of code I just add the link - but I can add my code also - it's just almost the same ..)
And Charlie, yes - this exactly what I'm try to do! But, I'd like that it will be done automatically - like, that I'll not have to change the code every while I'm create a new project (to a new month)
I'm thinking that perhaps you could benefit from the uDatefoldersy package perhaps? In the backoffice it structures your content in datefolders automatically and you can configure how you want it structured.
And for rendering you should be able to use the code provided by Charles above.
I tried to use the @your folder.Descendants() as Charlie suggested. The problem is however that I got an error. I'd assume that the reason for the error is because in my trees I have like some folders also, so for example if I have under "gadgets" section (which is content folder) also "2013" and "2014" then it will consider them as also child's and will try to handle them as pages?
So, how do I filter it that it will not includes the nodes that are content folders? (just news items = aka pages)
Thanks
So actually this is the code (it's much longer, but this two lines create the magic.. - aka , the magazine archive pages)
dynamic magazine_node = Library.NodeById(MagazineID); //get the right node according to the selected category
var magazine_pagesToList = magazine_node.Descendants().Where("Visible");
so actually MagazineID is the "folder" ID. So today I'm just using the ID of the 2013 folder (folder is content folder which is node on the tree of course) and it works. However, when I try to give MagazineID the value of the parent folder - for example, gadget, photography (or any other category at the magazine) which contain 2013 & 2014 content folders then it gives error. So the question is - how do I filter magazine_pageToList so it will get just the pages - aka, all the items which under 2013 and 2014 but not the nodes 2013, and 2014 (which are content folders)?
after the following lines there's a loop which just display the nodes which is the news items.
ahhh got you. you need a lambda expression.. What language are you using?
magazibe_node.Descendants().Where(x=>x.GetUmbracoPropertvalueValue("Visible) == 1 && x.DocTypeAlias != the doc type alias of the 2014 and 2013 folders)
Hi Charlie,
Thanks for your help. Unfortunately, it doesn't works yet...
When I try to use the Lambda expression I get the following Error:
"Archieve_Magazine.cshtml(181): error CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type"
"error CS1061: 'umbraco.NodeFactory.Node' does not contain a definition for 'Descendants' and no extension method 'Descendants' accepting a first argument of type 'umbraco.NodeFactory.Node' could be found (are you missing a using directive or an assembly reference?)"
Hi Charles,
Thanks a lot for your help.
So actually this solution didn't work cause I still got errors. So here's what I did - which now works:
I added the following line
Question about display nodes
Hello The way I store the nodes in my magazine is currently by years (2012 / 2013 / 2014) Now when I display the nodes (posts) I rub a loop on each year.
What I want to do now is to add months - then when I display the posts (nodes) list I'll have to "scan" each month - like when I'll run on the years node I'll have to go inside every month - is there any technique to do it? I thought maybe using recursion?
I made a small image to try illustrate what I try to achieve: at the right is what I have now, at the left is what I try to achieve
Thanks for your help
Hi Meni
What does your current razor code look like?
/Jan
I think what you are trying ask ia:
How do i get content from the bottom of the structure(a magazine item) given i have Year, Month, Day structure.
What you need i think is LINQ to get the descendants of each year folder where your document type alias == the document type alias you have given the magazine item).
Charlie :)
Hi Jan, So actually my code looks like the code here: http://umbraco.com/help-and-support/video-tutorials/umbraco-fundamentals/razor-recipes/news.aspx
(Because I used the code from this great tutorial :) , and in order to keep this tread clean and w/o lot of code I just add the link - but I can add my code also - it's just almost the same ..)
And Charlie, yes - this exactly what I'm try to do! But, I'd like that it will be done automatically - like, that I'll not have to change the code every while I'm create a new project (to a new month)
Thanks a lot :)
yea. If you do something like
@your folder.Descendants().Where(x=>x.DocumentTypeAlias == "your alias")
This will go down everynode under the your folder and return any content if finds for the specific document type.
So you want have to change any code :).
Charlie
Also dont forget to vote :P
http://our.umbraco.org/people/mvps
Hi Meni
I'm thinking that perhaps you could benefit from the uDatefoldersy package perhaps? In the backoffice it structures your content in datefolders automatically and you can configure how you want it structured.
And for rendering you should be able to use the code provided by Charles above.
Just a tip for the backoffice.
/Jan
http://our.umbraco.org/projects/developer-tools/autofolders thats pretty good as well. I dont know what you make of it Jan. Should i be using uDatefoldersy?
Charlie
Hi everyone ! Thanks for your replies.
I tried to use the @your folder.Descendants() as Charlie suggested. The problem is however that I got an error. I'd assume that the reason for the error is because in my trees I have like some folders also, so for example if I have under "gadgets" section (which is content folder) also "2013" and "2014" then it will consider them as also child's and will try to handle them as pages?
So, how do I filter it that it will not includes the nodes that are content folders? (just news items = aka pages) Thanks
Hi Meni
What error do you get and what does your code look like?
/Jan
Hi Meni, have you got the code you used?. The Descendants() will go down the tree from the root you specify and return as an IEnum
Charlie :)
sorry @Jan did not see the comment you had posted.
So actually this is the code (it's much longer, but this two lines create the magic.. - aka , the magazine archive pages)
so actually MagazineID is the "folder" ID. So today I'm just using the ID of the 2013 folder (folder is content folder which is node on the tree of course) and it works. However, when I try to give MagazineID the value of the parent folder - for example, gadget, photography (or any other category at the magazine) which contain 2013 & 2014 content folders then it gives error. So the question is - how do I filter magazine_pageToList so it will get just the pages - aka, all the items which under 2013 and 2014 but not the nodes 2013, and 2014 (which are content folders)?
after the following lines there's a loop which just display the nodes which is the news items.
This is the page for example the uses this loop: http://opli.net/Gadgets.aspx
ahhh got you. you need a lambda expression.. What language are you using?
magazibe_node.Descendants().Where(x=>x.GetUmbracoPropertvalueValue("Visible) == 1 && x.DocTypeAlias != the doc type alias of the 2014 and 2013 folders)
something like that
does that make sense?.
Charlie?
Hi Charlie, using Razor. Just a simple Razor Actually is base on this tutorial: http://umbraco.com/help-and-support/video-tutorials/umbraco-fundamentals/razor-recipes/news.aspx
Which variable is x? is it something I need to declare?
No x is dynamic its a lambda expression so it will respresent the type in this case a node
http://stackoverflow.com/questions/10097995/i-want-to-understand-the-lambda-expression-in-html-displayformodelitem-mymo
Also the site you posted is that yours?
So in this case magazibe_node.Descendants().Where(x=.x.
x would respresent the type of magazine_node :)
magazibe_node.Descendants() // desendants of not children of (will keep going down)
.Where (where something clause in the collection)
x=>x (dynamic respsents an item in the collection of its type (node))
.GetUmbracoPropertvalueValue("Visible) (we have accesss to this as x is type of node)
Also do not use dynamic
dynamic magazine_node
You wont have intellisense. Change dyanmic to the type that magazine_node and you will get intellisens for it
Hope that helps :)
Charlie
Hi Charlie, Thanks for your help. Unfortunately, it doesn't works yet... When I try to use the Lambda expression I get the following Error: "Archieve_Magazine.cshtml(181): error CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type"
This the code I use:
Now, even if instead dynamic magazine_node I'm use the following line:
I get the errors
Any idea...? Maybe I can filter through this line (which I'm currently using and with out the lambda expression)?
And yes, the link is from my website - which I built with Umbraco of course ... :)
Hi this is because at the moment mazineNode is dynamic. Your expression does not know the type
If you do
Node magazine_node = Library.NodeById(MagazineID);
var magazine_pagesToList = magazine_node.Descendants().Where(x=>x.GetUmbracoPropertvalueValue("Visible") == 1 && x.DocTypeAlias !="ContentFolder");
It will work fine :)
Charlie
Hi Charlie, So if I do so I get this error...
"error CS1061: 'umbraco.NodeFactory.Node' does not contain a definition for 'Descendants' and no extension method 'Descendants' accepting a first argument of type 'umbraco.NodeFactory.Node' could be found (are you missing a using directive or an assembly reference?)"
You also need a null check so it should be:
Node magazineNode = Library.NodeById(MagazineID);
{
if(magazinePages.count > 0)
{
// do something with them
}
}
Charlie :)
Ok what version of umbraco are you using?
{
if(magazinePages.count >0)
{
// do something with them
}
}
Hi Charles, Thanks a lot for your help. So actually this solution didn't work cause I still got errors. So here's what I did - which now works: I added the following line
Now it works!
Thanks again for the help
is working on a reply...