Copied to clipboard

Flag this post as spam?

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


  • Anthony Candaele 1197 posts 2049 karma points
    May 04, 2012 @ 11:30
    Anthony Candaele
    0

    DynamicNodeList does not contain a definition for 'Children'

    Hi,

    I'm trying to loop through all publications that are stored in a PublicationYearFolder. I'm filtering the publications on the publicationtype (article, book, bookchapter, conference proceeding) that was sent through a querystring.

    my code looks like this:

    @{

      var publicationtype = HttpContext.Current.Request.QueryString["type"];

      DynamicNodeList publications = new DynamicNodeList();

      if(publicationtype != null)

      {

          publications = @Model.PublicationFolderYear.Children.Where(Model.publicationType == publicationtype);

      }

      else

      {

          publications = @Model.PublicationFolderYear.Children.Where(Model.publicationType == "article");

      }

      }

    <h1>@publicationtype</h1>

    @foreach (DynamicNode publication in publications)

    {

    @publication.Name

    }

    The content tree looks like this:

     

    However, when debugging the Razor script, I get this error:

    'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Children'

    I don't understand this because when I write the line:

    publications = @Model.PublicationFolderYear.Children.Where(Model.publicationType == "article");

    I don't understand this, because in VS the Intellisense tells me that there is a 'Children' property

    What am I doing wrong?

    Thanks for your help,

    Anthony

  • Anthony Candaele 1197 posts 2049 karma points
    May 04, 2012 @ 11:55
    Anthony Candaele
    0

    my bad, giving this code a second look made me realise it couldn't work.

    This works though, all publicationyear folders are looped and every publication rendered:

    @{

      var publicationtype = HttpContext.Current.Request.QueryString["type"];

      DynamicNodeList yearfolders = new DynamicNodeList();

      yearfolders = @Model.Children;

      

      

      }

    <h1>@publicationtype</h1>

    @foreach (DynamicNode folder in yearfolders)

    {

        <h3>@folder.Name</h3>

        DynamicNodeList publications = folder.GetChildrenAsList;

        {

            foreach (DynamicNode publication in publications)

            {

                <p>@publication.Name;</p>

            }

        }

     

    }

    Now I just need to filter on 'publicationType'

  • Grant Thomas 291 posts 324 karma points
    May 04, 2012 @ 12:21
    Grant Thomas
    0

    Is `publicationType` just the Document Type Alias? If so, just do something like this:

    if (publication.NodeTypeAlias == publicationtype) {
      <p>@publication.Name</p>
  • Anthony Candaele 1197 posts 2049 karma points
    May 04, 2012 @ 13:55
    Anthony Candaele
    0

    Hi Grant,

    No, publicationType is a property of the 'publication' documentype of custom datatype dropdown list

    Thanks for your help,

    Anthony

  • Anthony Candaele 1197 posts 2049 karma points
    May 04, 2012 @ 14:24
    Anthony Candaele
    0

    and now the filtering on publicationtype is also solved:

    @using umbraco.MacroEngines

    @inherits umbraco.MacroEngines.DynamicNodeContext

     

    @{

      var publicationtype = HttpContext.Current.Request.QueryString["type"];

      DynamicNodeList yearfolders = new DynamicNodeList();

      yearfolders = @Model.Children;

      }

    <h1>@publicationtype</h1>

    @foreach (DynamicNode folder in yearfolders)

    {

        <h3>@folder.Name</h3>

        DynamicNodeList publications = folder.GetChildrenAsList;

        {

            foreach (DynamicNode publication in publications)

            {

                if (publication.GetProperty("publicationType").Value == publicationtype)

                {

                    @publication.Name;

                }

            }

        }

     

    }

  • Anthony Candaele 1197 posts 2049 karma points
    May 04, 2012 @ 15:13
    Anthony Candaele
    0

    tweaked the code a little:

    this code loops through all publicationyear folders, and if it finds a publiction of the publicationtype that was sent with the querystring, it adds the publication to a list of dynamic nodes, publist. At the end of each cycle through the publicationyearfolders there is a check to see if the publist has any items, if so, the publications are rendered.

    This way all publications are filtered by publicationtype and sorted by year:

    @using umbraco.MacroEngines
    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{
      var publicationtype HttpContext.Current.Request.QueryString["type"];
      DynamicNodeList yearfolders new DynamicNodeList();
      yearfolders @Model.Children;
      List<DynamicNodepublist new List<DynamicNode>();
      
      }
    <h1>@publicationtype</h1><br />
    @foreach (DynamicNode folder in yearfolders)
    {
        
        DynamicNodeList publications folder.GetChildrenAsList;
        {
            foreach (DynamicNode publication in publications)
            {
                if (publication.GetProperty("publicationType").Value == publicationtype)
                {
                    publist.Add(publication);
                }
            }
        }
        if (publist.Count(!= 0)
        {
            <h3>@folder.Name</h3>
            foreach (DynamicNode publication in publist)
            {
                 <p>@publication.GetProperty("publicationTitle").Value</p>
             }
             
        }
        
        publist.Clear();
    }

    Hope this might be usefull to someone else, wandering just like me through Razorland :)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies