Copied to clipboard

Flag this post as spam?

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


  • Meni 247 posts 483 karma points
    Mar 23, 2014 @ 19:52
    Meni
    0

    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 enter image description here

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Mar 23, 2014 @ 20:04
    Jan Skovgaard
    0

    Hi Meni

    What does your current razor code look like?

    /Jan

  • Charles Afford 1163 posts 1709 karma points
    Mar 23, 2014 @ 20:33
    Charles Afford
    0

    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 :)

  • Meni 247 posts 483 karma points
    Mar 23, 2014 @ 21:20
    Meni
    0

    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 :)

  • Charles Afford 1163 posts 1709 karma points
    Mar 23, 2014 @ 22:47
    Charles Afford
    0

    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

  • Charles Afford 1163 posts 1709 karma points
    Mar 23, 2014 @ 22:53
    Charles Afford
    0

    Also dont forget to vote :P

    http://our.umbraco.org/people/mvps

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Mar 23, 2014 @ 23:03
    Jan Skovgaard
    0

    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

  • Charles Afford 1163 posts 1709 karma points
    Mar 23, 2014 @ 23:07
    Charles Afford
    0

    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

  • Meni 247 posts 483 karma points
    May 12, 2014 @ 21:51
    Meni
    0

    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

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    May 12, 2014 @ 22:19
    Jan Skovgaard
    0

    Hi Meni

    What error do you get and what does your code look like?

    /Jan

  • Charles Afford 1163 posts 1709 karma points
    May 12, 2014 @ 22:23
    Charles Afford
    0

    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 :)

  • Charles Afford 1163 posts 1709 karma points
    May 12, 2014 @ 22:24
    Charles Afford
    0

    sorry @Jan did not see the comment you had posted.

  • Meni 247 posts 483 karma points
    May 13, 2014 @ 00:39
    Meni
    0

    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.

    This is the page for example the uses this loop: http://opli.net/Gadgets.aspx

  • Charles Afford 1163 posts 1709 karma points
    May 13, 2014 @ 00:46
    Charles Afford
    0

    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?

     

     

  • Meni 247 posts 483 karma points
    May 13, 2014 @ 00:49
    Meni
    0

    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?

  • Charles Afford 1163 posts 1709 karma points
    May 13, 2014 @ 00:52
    Charles Afford
    0

    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?

  • Charles Afford 1163 posts 1709 karma points
    May 13, 2014 @ 00:54
    Charles Afford
    0

    So in this case magazibe_node.Descendants().Where(x=.x.

    x would respresent the type of magazine_node :)

  • Charles Afford 1163 posts 1709 karma points
    May 13, 2014 @ 01:00
    Charles Afford
    0

    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

  • Meni 247 posts 483 karma points
    May 14, 2014 @ 23:44
    Meni
    0

    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:

    dynamic magazine_node = Library.NodeById(MagazineID);
    var magazine_pagesToList = magazine_node.Descendants().Where(x=>x.GetUmbracoPropertvalueValue("Visible") == 1 && x.DocTypeAlias != "ContentFolder");
    

    Now, even if instead dynamic magazine_node I'm use the following line:

    var magazine_node = new Model(MagazineID);
    

    I get the errors

    Any idea...? Maybe I can filter through this line (which I'm currently using and with out the lambda expression)?

    var magazine_pagesToList = magazine_node.Children.Where("Visible");
    

    And yes, the link is from my website - which I built with Umbraco of course ... :)

  • Charles Afford 1163 posts 1709 karma points
    May 14, 2014 @ 23:51
    Charles Afford
    0

    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

  • Meni 247 posts 483 karma points
    May 14, 2014 @ 23:56
    Meni
    0

    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?)"

  • Charles Afford 1163 posts 1709 karma points
    May 14, 2014 @ 23:56
    Charles Afford
    0

    You also need a null check so it should be:

    Node magazineNode = Library.NodeById(MagazineID);
    if(magazineNode != null)
    {
    IEnumerable<node> magazinePages.Descendants().Where(x=>x.GetUmbracoPropertvalueValue("Visible") == 1 && x.DocTypeAlias !="ContentFolder");
    if(magazinePages.count > 0)
    {
    // do something with them
    }
    }

    Charlie :)

  • Charles Afford 1163 posts 1709 karma points
    May 14, 2014 @ 23:59
    Charles Afford
    0

    Ok what version of umbraco are you using?  

  • Charles Afford 1163 posts 1709 karma points
    May 15, 2014 @ 00:03
    Charles Afford
    0
    DynamicNode magazineNode =new DynamicNode(MagazineID);
    if(magazineNode !=null)
    {
    IEnumerable<DynamicNode>magazinePages.Descendants().Where(x=>x.GetUmbracoPropertvalueValue("Visible")==1&& x.DocTypeAlias!="ContentFolder");
    if(magazinePages.count >0)
    {
    // do something with them
    }
    }
  • Meni 247 posts 483 karma points
    May 29, 2014 @ 08:41
    Meni
    0

    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

    magazine_pagesToList = magazine_node.DescendantsOrSelf().Where("NodeTypeAlias == @0", "NewsPage");
    

    Now it works!

    Thanks again for the help

Please Sign in or register to post replies

Write your reply to:

Draft