Copied to clipboard

Flag this post as spam?

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


  • Toni Becker 146 posts 425 karma points
    Jul 31, 2011 @ 14:36
    Toni Becker
    0

    DynamicNodeProblem 4.7.1

    Hy i'm using latest MacroEngines Build. Now the problem.

    I do the following with my code:

    @{
    var start = Model.AncestorOrSelf(1).Descendants("FolderArticles");
    var articles = start.Descendants("articlePost");
    }
    @foreach(var c in articles)
    {
    <h2>@n.contentTitle</h2>...
    }

    But it's throwing an error umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Descendants'

    Some ideas? Looked through the Wiki @ http://our.umbraco.org/wiki/reference/code-snippets/razor-snippets/dynamicnode-%28and-model%29-members-and-properties and there i see it should be possible to acces Descendants from DynamicNodeList

  • Toni Becker 146 posts 425 karma points
    Jul 31, 2011 @ 16:21
    Toni Becker
    0

    Tested this but wont work:

    @using umbraco.MacroEngines
    @using System.Linq
    @using System.Xml.Linq

    @{
        var nodes = Model.AncestorOrSelf(1).Descendants("FolderArticle");
    }

    @foreach(dynamic news in ((DynamicNodeList)nodes).myArticle)
    {
        foreach(dynamic n in news)
        {
            <p>@n.Url</p>
        }
    }

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Jul 31, 2011 @ 22:22
    Anthony Dang
    0

    The reason your code doesnt work is because you call Descendants() in the first line which gives you a DynamicNodeList, then you call Decendants on that. I assume that you only have a single FolderArticles node right?

    If so, you need to do something like this...

    @{

    // get current node
    var current = new DynamicNode(Model.Id)

    // get a single FolderArticles node
    var start = current.AncestorOrSelf(1).Descendants("FolderArticles").Items.Single();

    // get descendants of type articlePost
    var articles = start.Items.Descendants("articlePost");
    }

    @foreach(var c in articles)
    {
    <h2>@n.contentTitle</h2>...
    }

     

    If you have multiple FolderArticle nodes then you need to iterate over all of them.

    Hope that helps.

    ps. you should rename articlePost to ArticlePost.


  • Toni Becker 146 posts 425 karma points
    Aug 01, 2011 @ 12:18
    Toni Becker
    0

    Hmm won't work, throws an error:

    Error loading Razor Script TabTest.cshtml
    c:\inetpub\wwwroot\kultmark\macroScripts\TabTest.cshtml(19): error CS1061: 'object' does not contain a definition for 'nodeName' and no extension method 'nodeName' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

    Where do you have the input from with the .Items.Single() never read about this before.

    Greetings

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Aug 01, 2011 @ 13:30
    Anthony Dang
    0

    You're now using a DynamicNode object

    Sorry n.contentTitle should be n.GetProperty("contentTitle")

    You also need using System.Linq

    Can you paste your script?


  • Toni Becker 146 posts 425 karma points
    Aug 01, 2011 @ 14:15
    Toni Becker
    0

    @using umbraco.MacroEngines
    @using System.Linq
    @using System.Xml.Linq
        
        @{

    // get current node
    var current = new DynamicNode(Model.Id)

    // get a single FolderArticles node
    var start = current.AncestorOrSelf(1).Descendants("FolderArticlesl").Items.Single();

    // get descendants of type articlePost
    var articles = start.Items.Descendants("ArticlePost");
    }

    @foreach(var c in articles)
    {
    <h2>@c.GetProperty("contentTitle")/h2>
    }

    nothing is returned now. The Errors are gone but the content although :). E.G. I have more than one "FolderArticles"

    The Structure is the Following:

    Content->Locations->Articles

    and each Location has its own ArticleArea from Type FolderArticles where the ArticlePost is stored.

  • 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