Copied to clipboard

Flag this post as spam?

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


  • Steve 472 posts 1216 karma points
    May 28, 2014 @ 17:03
    Steve
    0

    Outputting a Node List from a MultiNode Tree Picker

    I have a News content page that I would like only NewsArticles selected by a MultiNode Content Picker. I had thought I had looked up the correct way to implement this, but the script is not loading on the page. Here is my Razor. Any help would be appreciated. Thanks!

    @using umbraco.MacroEngines
    @using umbraco;
    @inherits umbraco.MacroEngines.DynamicNodeContext
    
        @{
            var category = Model.AncestorOrSelf("NewsCategory");
    
       if (category.Children.HasValue("mntpFeaturePickerXML"))
        {
            int[] nodeList = uQuery.GetXmlIds(Model.mntpFeaturePickerXML.ToXml());      
            IEnumerable<DynamicNode> PublishedNodeList = Library.NodesById(nodeList.ToList());        
            PublishedNodeList = PublishedNodeList.Where(x => x.GetType() != typeof(DynamicNull) && x.Id > 0);                        
            dynamic multiNodeTreePicker = new DynamicNodeList(PublishedNodeList);
        <div id ="recent-news">
            <h3>@category.Name</h3>
                </div>
            <div class="news-listing">
    
            if (multiNodeTreePicker.Any())
                <ul>
            {
                @foreach (var item in multiNodeTreePicker.Where("Visible"))
                {                   
                    <li>@item.Name</li>      
                }               
            }
            </ul>
                </div>
        } 
    }
  • Fuji Kusaka 2203 posts 4220 karma points
    May 28, 2014 @ 17:10
    Fuji Kusaka
    0

    Hi Steve,

    Not sure but why are you using MultinodeTreePicker to display NewItems with a specific DocType ?

    Why not Displaying those Specific DocType and using umbracoNaviHide to hide the ones you dont want to display ?

    //fuji

  • Steve 472 posts 1216 karma points
    May 28, 2014 @ 17:16
    Steve
    0

    It's not just a specific DocType, it is selected articles to display under a specific page or NewsCategory. I have multiple NewsCategories, but in some cases I would like NewsArticles from one NewsCategory to also be displayed under a different NewsCategory as well. Do you understand?

  • Steve 472 posts 1216 karma points
    May 28, 2014 @ 22:00
    Steve
    0

    I am stuck. Been working on this all day. My problem is I don't know how to get the value of the property of my multiNodePicker and then compair to see if it is on currentPage or Model and output the nodes selected with multiNodePicker in a list. Any help would be appreciated. Here is what I have now. The first part makes a separate list of "featureThisArticle" and it works fine. The "sidebarArticles" is the problem.

    @{
            var category = Model.AncestorOrSelf("NewsCategory");
            var featuredArticles = category.Descendants("NewsArticle").Where("featureThisArticle").Take(9);
            var sidebarArticles = category.Descendants("NewsArticle").HasValue("newsZones");
    
    <div class="featured-articles">
        <div class="featured-listings">
    
            @foreach(var article in featuredArticles)
            {
        var articleName = article.HasValue("shortPageTitle") ? @article.shortPageTitle : article.HasValue("pageTitle") ? @article.pageTitle : @article.pageName;
            <div class="listing">
                <p class="tag">@category.Name</p>
                    @if ( article.Media("featuredImage") != null ) {
                    var image = article.Media("featuredImage").umbracoFile;
                        <img src="/ImageGen.ashx?image=@image&width=154" />
                        }
                    <div class="listing-content">
                        <h3>@articleName</h3>
    
                        <p><a href="@article.Url">Read More</a></p>
                    </div>
            </div>
            }
        </div>
    </div>
    
    @*------------------------sidebarArticles-------------------------------    *@
    
        <div id ="recent-news">
            <h3>RECENT @category.Name</h3>
        </div>    
       if (category.Descendants("NewsArticle").HasValue("newsZones"))
        {
            <div class="news-listing">
                    <p>@category.pageTitle</p>
                <ul>
    
                @foreach (var item in sidebarArticles)
                {    
                    <li>@item.pageTitle</li>                 
                }
                </ul>
            </div>
        } 
        <div class="recent-news-footer"></div>  
    }
  • Steve 472 posts 1216 karma points
    May 28, 2014 @ 22:01
    Steve
    0

    Sorry, "newsZones" is the alias of the multiNodePicker
      

  • Neil Hodges 338 posts 987 karma points
    May 29, 2014 @ 10:43
    Neil Hodges
    0

    Hi Steve

    Where is it breaking? Have you stepped through your code? I think i would do this:

    var sidebarArticles = category.Descendants("NewsArticle").Where(x => x.GetPropertyValue("newsZones"));

    then

    if (sidebarArticles.Any())
        {
            <div class="
    news-listing">
                    <p>@category.pageTitle</p>
                <ul>

                @foreach (var item in sidebarArticles)
                {    
                    <li>@item.GetPropertyvalue("
    pageTitle")</li>                
                }
                </ul>
            </div>
        }

    Not tested but i would think at the minute sidebarAtricles would return a boolean as you have .HasValue() on the end?

  • Steve 472 posts 1216 karma points
    May 29, 2014 @ 14:21
    Steve
    0

    Is there another way to iterate through the values of the picker? I am using Umbraco 4.11 and the lambda is giving me a casting 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". 

     

  • Steve 472 posts 1216 karma points
    May 29, 2014 @ 15:21
    Steve
    0

    I got the razor to save without errors by using uQuery, but the script still won't load on the page.

    var sidebarArticles = uQuery.GetNode(5580).GetDescendantNodes(n => n.NodeTypeAlias == "NewsArticle").OrderByDescending(x => x.GetProperty("newsZones"));
    if (sidebarArticles.Any())
        {
            <div class="news-listing">
                    <p>@category.pageTitle</p>
                <ul>
    
                @foreach (var item in sidebarArticles)
                {    
                    <li>@item.GetProperty("pageTitle")</li>                 
                }
                </ul>
            </div>
        } 
  • Neil Hodges 338 posts 987 karma points
    May 29, 2014 @ 15:57
    Neil Hodges
    0

    Hi Steve

    I'll fire up an instance of 4.11 and mock what you have, the MNTP you have is that set to use CSV?

    Am i right in thinking your structure looks like this:

    NewsCategory
    --
    NewsArticle (<--newsZone is the alias of MNTP inside here?)
    -- NewsArticle
    -- NewsArticle
    -- so on...
  • Steve 472 posts 1216 karma points
    May 29, 2014 @ 15:59
    Steve
    0

    Neil,

    The picker is using xslt and you have the structure correct.Thank for your help. 

  • Neil Hodges 338 posts 987 karma points
    May 29, 2014 @ 16:16
    Neil Hodges
    0

    When you say XSLT you mean the data is XML? not CSV yes?

  • Steve 472 posts 1216 karma points
    May 29, 2014 @ 16:17
    Steve
    0

    Sorry, :) Yes, that is what I ment.

  • Neil Hodges 338 posts 987 karma points
    May 29, 2014 @ 16:43
    Neil Hodges
    0

    Ok give this a whirl

     var sidebarArticles = category.Descendants("NewsArticle").Where("newsZones");
    

    then iterate over them like this

    @{
        if (sidebarArticles.Any())
        {
            int[] nodeList = uQuery.GetXmlIds(sidebarArticles.newsZones.ToXml());      
            IEnumerable<DynamicNode> publishedNodeList = Library.NodesById(nodeList.ToList());        
            publishedNodeList = publishedNodeList.Where(x => x.GetType() != typeof(DynamicNull) && x.Id > 0);                        
            dynamic multiNodeTreePicker = new DynamicNodeList(publishedNodeList);
    
            if (multiNodeTreePicker.Any())
            {
                foreach (var item in multiNodeTreePicker.Where("Visible"))
                {                   
                    <p>@item.Name</p>      
                }               
            }
        } 
    }

     

    Make sure the nodes are published, in some cases ive had to re publish the nodes as they havnt been picked up before

     

     

     

     

     

     

     

     

     

     

  • Steve 472 posts 1216 karma points
    May 29, 2014 @ 17:21
    Steve
    0

    Neil, this loads on the page, but it's not pulling in any of the NewsArticles that had a NewsCategory node selected for that NewsArticle usind the MNTP. I believe this was the first way I had tried to accomplish this. Here is a screen capture of my tree and the NewsCategory that the NewsArticle should be listed on the newsZone "Rose-Hulman Commencement 2012".

  • Neil Hodges 338 posts 987 karma points
    May 29, 2014 @ 17:29
    Neil Hodges
    0

    Ok, so the Macro youve created holding the Razor code, where is that added? On the Template? On the News landing page via a RTE?

  • Steve 472 posts 1216 karma points
    May 29, 2014 @ 17:31
    Steve
    0

    On the Template for NewsCategory.

  • Neil Hodges 338 posts 987 karma points
    May 29, 2014 @ 17:58
    Neil Hodges
    0

    Ok tested this and its showing each newsZone selected in each Newsarticle;

    @using Umbraco.Core
    @using umbraco.MacroEngines
    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
        var category = Model.AncestorOrSelf("NewsCategory");
        var sidebarArticles = category.Descendants("NewsArticle");
    
    @*------------------------sidebarArticles-------------------------------    *@
       
        if (sidebarArticles.Any())
        {
        <ul>
            @foreach (var item in sidebarArticles)
            {
                    if (item.GetPropertyValue("newsZones").ToString() != "")
                    {
                        int[] nodeList = uQuery.GetXmlIds(item.newsZones.ToXml());
                        IEnumerable<DynamicNode> publishedNodeList = Library.NodesById(nodeList.ToList());
                        publishedNodeList = publishedNodeList.Where(x => x.GetType() != typeof(DynamicNull) && x.Id > 0);
                        dynamic multiNodeTreePicker = new DynamicNodeList(publishedNodeList);
    
                        if (multiNodeTreePicker.Any())
                        {
                            foreach (var Inneritem in multiNodeTreePicker.Where("Visible"))
                            {
                                    <li>@Inneritem.Name</li>   
                            }
                        }
                    }
                
            }
        </ul>
        } 
        <div class="recent-news-footer"></div>  
    }

     

     

     

     

     

     

  • Steve 472 posts 1216 karma points
    May 29, 2014 @ 18:25
    Steve
    0

    Sorry, but this still isn't loading on the page, and I think I might not be explaining what I am trying to achieve well.

    On any NewsArticle I would like to, using the MNTP select the page (the node of any NewsCategory) and have that NewsArticle display in a list on that selected NewsCategory.

     

  • Neil Hodges 338 posts 987 karma points
    May 29, 2014 @ 18:40
    Neil Hodges
    0

    Yep dont think im getting what your trying to achieve.

    So this is what im now thinking - On every Category Page you have a side bar that needs to iterate through each NewsArticle and see it has been assigned to the NewsCategory via the NewsZone MNTP - that sound correct?

  • Neil Hodges 338 posts 987 karma points
    May 29, 2014 @ 19:00
    Neil Hodges
    0

    Ok hopefully this will work as expected, this iterates over the News nodes, looks into each NewsArticle and see's if the CategoryPage has been added to the NewsArticle, if so it shows the name of the newsArticle - This is for the sidebar only, you can add your code for the featured section to the top of it, i removed it for brevity

    @using Umbraco.Core
    @using umbraco.MacroEngines
    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
        var RelatedNews = new DynamicNodeList();
        var AllNews = Model.AncestorOrSelf("News").Children();
    
    @*------------------------sidebarArticles-------------------------------    *@
       
        if (AllNews.Any())
        {
            <ul>
                
                @foreach (var item in AllNews)
                {
                    //NewsCategories
                    if (item.Children().Any())
                    {
                        foreach (var innerItem in item.Children())
                        {
                            //NewsArticles
                            if (innerItem.GetPropertyValue("newsZones").ToString() != "")
                            {
                                int[] nodeList = uQuery.GetXmlIds(innerItem.newsZones.ToXml());
                                IEnumerable<DynamicNode> publishedNodeList = Library.NodesById(nodeList.ToList());
                                publishedNodeList = publishedNodeList.Where(x => x.GetType() != typeof(DynamicNull) && x.Id > 0);
                                dynamic multiNodeTreePicker = new DynamicNodeList(publishedNodeList);
                                
                                if (multiNodeTreePicker.Any())
                                {
                                    foreach (var subitem in multiNodeTreePicker.Where("Visible"))
                                    {
                                        //NewsZones
                                        if (subitem.Name == Model.Name)
                                        {
                                            RelatedNews.Add(innerItem);
                                        }                                      
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (item.HasValue("newsZones"))
                        {
                            int[] nodeList = uQuery.GetXmlIds(item.newsZones.ToXml());
                            IEnumerable<DynamicNode> publishedNodeList = Library.NodesById(nodeList.ToList());
                            publishedNodeList = publishedNodeList.Where(x => x.GetType() != typeof(DynamicNull) && x.Id > 0);
                            dynamic multiNodeTreePicker = new DynamicNodeList(publishedNodeList);
    
                            if (multiNodeTreePicker.Any())
                            {
                                foreach (var subitem in multiNodeTreePicker.Where("Visible"))
                                {
                                    //NewsZones
                                    if (subitem.Name == Model.Name)
                                    {
                                        RelatedNews.Add(item);
                                    }
                                }
                            }
                        }
                    }
                }
                
                @if (RelatedNews.Any())
                {
                    foreach (var assocNewsItem in RelatedNews)
                    {
                        <li>
                            @assocNewsItem.Name
                        </li>
                    }
                }
            </ul>
        } 
        <div class="recent-news-footer"></div>  
    }

    Ive tested this within in my setup and it works fine, let me know how you get on.

  • Steve 472 posts 1216 karma points
    May 29, 2014 @ 20:00
    Steve
    0

    It won't load in the page if the var AllNews = Model.AncestorOrSelf("News").Children()

    only if I take off Children(), and then there is nothing pulled in.

    Sorry, this has not been easy. I have no idea why it's not working.

  • Neil Hodges 338 posts 987 karma points
    May 29, 2014 @ 20:04
    Neil Hodges
    0

    Whats the top level Alias of News Node? I called mine 'News' yours may be different, just change the "News" to your alias

  • Steve 472 posts 1216 karma points
    May 29, 2014 @ 20:05
    Steve
    0

    Yeah, I noticed that and had allready changed my code to be NewsHome. I didn't want to confuse you in my last post, but it still doesn't work.

  • Neil Hodges 338 posts 987 karma points
    May 29, 2014 @ 20:11
    Neil Hodges
    0

    Then im not sure whats going on, as mine displays correctly

  • Neil Hodges 338 posts 987 karma points
    May 29, 2014 @ 20:13
    Neil Hodges
    0

    Can you check the erro logs to see if its throwing an exception

  • Steve 472 posts 1216 karma points
    May 29, 2014 @ 20:14
    Steve
    0

    No I don't have access to the install directory. Sucks right?

  • Neil Hodges 338 posts 987 karma points
    May 29, 2014 @ 20:21
    Neil Hodges
    0

    Ah yes that does suck, it would be handy to see, im sure its something or nothing causing it not to render anything out. i dont suppose you have access to the web.config then either to turn on umbracoDebugMode ?

  • Neil Hodges 338 posts 987 karma points
    May 29, 2014 @ 20:24
    Neil Hodges
    0

    Ok lets see if we can bubble up the exception in code

    @using Umbraco.Core
    @using umbraco.MacroEngines
    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
        var RelatedNews = new DynamicNodeList();
        var AllNews = Model.AncestorOrSelf("News").Children();
        var errormessage = "";
    
    @*------------------------sidebarArticles-------------------------------    *@
       
        if (AllNews.Any())
        {
            try
            {
                <ul>
                
                @foreach (var item in AllNews)
                {
                    //NewsCategories
                    if (item.Children().Any())
                    {
                        foreach (var innerItem in item.Children())
                        {
                            //NewsArticles
                            if (innerItem.GetPropertyValue("newsZones").ToString() != "")
                            {
                                int[] nodeList = uQuery.GetXmlIds(innerItem.newsZones.ToXml());
                                IEnumerable<DynamicNode> publishedNodeList = Library.NodesById(nodeList.ToList());
                                publishedNodeList = publishedNodeList.Where(x => x.GetType() != typeof(DynamicNull) && x.Id > 0);
                                dynamic multiNodeTreePicker = new DynamicNodeList(publishedNodeList);
                                
                                if (multiNodeTreePicker.Any())
                                {
                                    foreach (var subitem in multiNodeTreePicker.Where("Visible"))
                                    {
                                        //NewsZones
                                        if (subitem.Name == Model.Name)
                                        {
                                            RelatedNews.Add(innerItem);
                                        }                                      
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (item.HasValue("newsZones"))
                        {
                            int[] nodeList = uQuery.GetXmlIds(item.newsZones.ToXml());
                            IEnumerable<DynamicNode> publishedNodeList = Library.NodesById(nodeList.ToList());
                            publishedNodeList = publishedNodeList.Where(x => x.GetType() != typeof(DynamicNull) && x.Id > 0);
                            dynamic multiNodeTreePicker = new DynamicNodeList(publishedNodeList);
    
                            if (multiNodeTreePicker.Any())
                            {
                                foreach (var subitem in multiNodeTreePicker.Where("Visible"))
                                {
                                    //NewsZones
                                    if (subitem.Name == Model.Name)
                                    {
                                        RelatedNews.Add(item);
                                    }
                                }
                            }
                        }
                    }
                }
                
                @if (RelatedNews.Any())
                {
                    foreach (var assocNewsItem in RelatedNews)
                    {
                        <li>
                            @assocNewsItem.Name
                        </li>
                    }
                }
            </ul>
            }
            catch (Exception ex)
            {
    
                errormessage = ex.StackTrace.ToString();
            }
            
        } 
        <div>
            @errormessage
        </div>
        <div class="recent-news-footer"></div>  
    }

     

    Ive wrapped it in a try catch block to see if it'll show the exception, try this

     

  • Neil Hodges 338 posts 987 karma points
    May 29, 2014 @ 20:32
    Neil Hodges
    0

    Oh and just a thought change:

    var AllNews = Model.AncestorOrSelf("News").Children();
    

    to

    var AllNews = Model.AncestorOrSelf("News").Children;
    

     

    as the brackets () at the end may be be the problem, ive had it in older instances, my version od Umbraco is 4.11.10

     

     

     

     

     

     

  • Steve 472 posts 1216 karma points
    May 29, 2014 @ 20:38
    Steve
    0

    Here is the exception:

    at CallSite.Target(Closure , CallSite , Object ) at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0) at ASP._Page_macroScripts_NewsCategory_cshtml.Execute() in \\umbracoshare\prep\wwwroot\macroScripts\NewsCategory.cshtml:line 55

  • Steve 472 posts 1216 karma points
    May 29, 2014 @ 20:42
    Steve
    0

    I now removed the () after Children and here is the exception:

    at CallSite.Target(Closure , CallSite , Object ) at ASP._Page_macroScripts_NewsCategory_cshtml.Execute() in \\umbracoshare\prep\wwwroot\macroScripts\NewsCategory.cshtml:line 55

  • Neil Hodges 338 posts 987 karma points
    May 29, 2014 @ 21:08
    Neil Hodges
    0

    Have you made sure your macro has this at the top?

    @using Umbraco.Core
    @using umbraco.MacroEngines

     

  • Steve 472 posts 1216 karma points
    May 29, 2014 @ 21:10
    Steve
    0

    These are the namespaces:

    @using Umbraco.Core

    @using umbraco.MacroEngines

    @inherits umbraco.MacroEngines.DynamicNodeContext

  • Neil Hodges 338 posts 987 karma points
    May 29, 2014 @ 21:14
    Neil Hodges
    0

    Ok so it seems to be failing at line 55, which i think is the object 'dynamic' it doesnt like, can we change

    catch (Exception ex)
            {
    
                errormessage = ex.StackTrace.ToString();
            }

    to

    catch (Exception ex)
            {
    
                errormessage = ex.Message.ToString();
            }

    see if it shows us anything else.

    Other than that it has to be the way it iterates over the MNTP

     

     

     

     

     

     

  • Steve 472 posts 1216 karma points
    May 29, 2014 @ 21:17
    Steve
    0

    Message: Cannot perform runtime binding on a null reference.

  • Neil Hodges 338 posts 987 karma points
    May 29, 2014 @ 21:26
    Neil Hodges
    0

    Must be a null refrence on the publishedNodeList, try this now ive added a check for nulls

    @using Umbraco.Core
    @using umbraco.MacroEngines
    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
        var RelatedNews = new DynamicNodeList();
        var AllNews = Model.AncestorOrSelf("News").Children;
        var errormessage = "";
    
    @*------------------------sidebarArticles-------------------------------    *@
       
        if (AllNews.Any())
        {
            try
            {
                <ul>
                
                @foreach (var item in AllNews)
                {
                    //NewsCategories
                    if (item.Children().Any())
                    {
                        foreach (var innerItem in item.Children())
                        {
                            //NewsArticles
                            if (innerItem.GetPropertyValue("newsZones").ToString() != "")
                            {
                                int[] nodeList = uQuery.GetXmlIds(innerItem.newsZones.ToXml());
                                IEnumerable<DynamicNode> publishedNodeList = Library.NodesById(nodeList.ToList());
                                if (publishedNodeList != null)
                                {
                                    publishedNodeList = publishedNodeList.Where(x => x.GetType() != typeof(DynamicNull) && x.Id > 0);
                                    dynamic multiNodeTreePicker = new DynamicNodeList(publishedNodeList);
    
                                    if (multiNodeTreePicker.Any())
                                    {
                                        foreach (var subitem in multiNodeTreePicker.Where("Visible"))
                                        {
                                            //NewsZones
                                            if (subitem.Name == Model.Name)
                                            {
                                                RelatedNews.Add(innerItem);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (item.HasValue("newsZones"))
                        {
                            int[] nodeList = uQuery.GetXmlIds(item.newsZones.ToXml());
                            IEnumerable<DynamicNode> publishedNodeList = Library.NodesById(nodeList.ToList());
                            if (publishedNodeList != null)
                            {
                                publishedNodeList = publishedNodeList.Where(x => x.GetType() != typeof(DynamicNull) && x.Id > 0);
                                dynamic multiNodeTreePicker = new DynamicNodeList(publishedNodeList);
    
                                if (multiNodeTreePicker.Any())
                                {
                                    foreach (var subitem in multiNodeTreePicker.Where("Visible"))
                                    {
                                        //NewsZones
                                        if (subitem.Name == Model.Name)
                                        {
                                            RelatedNews.Add(item);
                                        }
                                    }
                                }
                            }  
                        }
                    }
                }
                
                @if (RelatedNews.Any())
                {
                    foreach (var assocNewsItem in RelatedNews)
                    {
                        <li>
                            @assocNewsItem.Name
                        </li>
                    }
                }
            </ul>
            }
            catch (Exception ex)
            {
    
                errormessage = ex.StackTrace.ToString();
            }
            
        } 
        <div>
            @errormessage
        </div>
        <div class="recent-news-footer"></div>  
    }
  • Steve 472 posts 1216 karma points
    May 29, 2014 @ 21:37
    Steve
    0

    Still the same error message.

  • Neil Hodges 338 posts 987 karma points
    May 29, 2014 @ 21:48
    Neil Hodges
    0

    Its defo something around line 55, take everything out of the else statement and see if it still errors

  • Steve 472 posts 1216 karma points
    May 29, 2014 @ 21:50
    Steve
    0

    Yes, even if the else is empty.

  • Neil Hodges 338 posts 987 karma points
    May 29, 2014 @ 21:55
    Neil Hodges
    0

    I can't understand why it wont work, i have my version here working fine, i can't even reproduce the error. Without being able to debug the razor code step by step in Visual Studio your gonna be a bit screwed bud

    Do you not have a dev version you can debug? set Breakpoint and step through the code to see why its erroring? Are you making changes to a live site?

  • Steve 472 posts 1216 karma points
    May 30, 2014 @ 14:10
    Steve
    0

    Is there a way to have Visual Studio recognize Razor syntax? I was unaware of this. I'll look into how to do this. Thanks for all your efforts!

  • Steve 472 posts 1216 karma points
    May 30, 2014 @ 22:40
    Steve
    0

    I was able to move past the error at line 55, by removing the "ToString()". GetPropertyValue() allready returns a string and I've allready checked to see if it HasValue("newsZones"). 

    The next place it gets stuck at is line 58, with this error: 

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

    Any ideas?

  • Neil Hodges 338 posts 987 karma points
    May 30, 2014 @ 23:22
    Neil Hodges
    0

    Im assuming your using master pages and the site is a web forms site, it may not be able to access MVC properties like .ToXml()

    I would change the DataType MNTP to use CSV instead of XML, is their any specific reason why you need it to return XML?

  • Steve 472 posts 1216 karma points
    Jun 02, 2014 @ 14:48
    Steve
    0

    You are correct Neil, we are using masterpages and webforms. I will change the datatype of the MNTP to use CSV. How does the syntax change for the code?

  • Steve 472 posts 1216 karma points
    Jun 02, 2014 @ 15:43
    Steve
    0

    I inserted the code example from the MNTP component documentation page, but I get the error message "Cannot instantiate a DynamicNode without an id".

  • Steve 472 posts 1216 karma points
    Jun 02, 2014 @ 15:59
    Steve
    0

    Here is what I am using to pull the CSV from the MNTP.

           
        <div id ="recent-news">
            <h3>RECENT category.Name</h3>
        </div>
    
          if (AllNews.Any())
        {
            try
            {
                <ul>
    
                @foreach (var item in AllNews)
                {
                    //NewsCategories
                    if (item.Children().Any())
                    {
                        foreach (var innerItem in item.Children)
                        {
                            //NewsArticles
                            if (innerItem.GetPropertyValue("newsZones") != null)
                            {
                                IEnumerable<DynamicNode> PublishedNodeList = Library.NodesById(Model.newsZones.Split(','));        
                                PublishedNodeList = PublishedNodeList.Where(x => x.GetType() != typeof(DynamicNull) && x.Id > 0);                        
                                dynamic multiNodeTreePicker = new DynamicNodeList(PublishedNodeList);
    
    
                                    if (multiNodeTreePicker.Any())
                                    {
                                        foreach (var subitem in multiNodeTreePicker.Where("Visible"))
                                        {
                                            //NewsZones
                                            if (subitem.Name == Model.Name)
                                            {
                                                RelatedNews.Add(innerItem);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (item.HasValue("newsZones"))
                        {
                            IEnumerable<DynamicNode> PublishedNodeList = Library.NodesById(Model.newsZones.Split(','));        
                            PublishedNodeList = PublishedNodeList.Where(x => x.GetType() != typeof(DynamicNull) && x.Id > 0);                        
                            dynamic multiNodeTreePicker = new DynamicNodeList(PublishedNodeList);
    
    
                                if (multiNodeTreePicker.Any())
                                {
                                    foreach (var subitem in multiNodeTreePicker.Where("Visible"))
                                    {
                                        //NewsZones
                                        if (subitem.Name == Model.Name)
                                        {
                                            RelatedNews.Add(item);
                                        }
                                    }
                                }
                            }  
                        }
                    }
                }
    
                @if (RelatedNews.Any())
                {
                    foreach (var assocNewsItem in RelatedNews)
                    {
                        <li>
                            @assocNewsItem.Name
                        </li>
                    }
                }
            </ul>
            }
            catch (Exception ex)
            {
    
                errormessage = ex.Message.ToString();
            }
    
        } 
        <div>
            @errormessage
        </div>
        <div class="recent-news-footer"></div>  
    }
  • Neil Hodges 338 posts 987 karma points
    Jun 02, 2014 @ 16:08
    Neil Hodges
    0

    I'll have a look this evening, im in the UK so middle of the day here.

    I think i cant reproduce your problem as my test site was MVC. im going to try and re create it this evening using WebForms and Masterpages.

    Then i'll send over the code.

    Can you confirm what version of Umbraco your using - you said 4.11, is that 4.11.0? do you know the minor version 4.11.??

     

     

  • Steve 472 posts 1216 karma points
    Jun 02, 2014 @ 16:10
    Steve
    0

    It's 4.11.8

    I am sorry, I thought I has said I was using Webforms earlier. Thanks for your help.

  • Steve 472 posts 1216 karma points
    Jun 13, 2014 @ 14:58
    Steve
    0

    Has anyone got any suggestions? I am still unable to get this to work.

Please Sign in or register to post replies

Write your reply to:

Draft