Copied to clipboard

Flag this post as spam?

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


  • Nicolai 48 posts 201 karma points
    Apr 20, 2015 @ 11:47
    Nicolai
    0

    Partial View Macro doesn't render?

    So i got this code which does not work when I try to convert from Scripting Macro to Partial View Macro, can anyone help me out?

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @using System.Xml.XPath;
    @using System.Xml;
    @{

    <br /><br />
        var startNode = Umbraco.Content(4478);
        
        if (startNode.Children.Where("Visible").Any())
        {
            foreach (var page in startNode.Children.Where("Visible"))
            { 
              if (page.DocumentTypeAlias == "RecommendedFooterBox")
              {
                <div class="rss-footer-box col-xs-6 col-sm-3">
                  <h4>@page.recBoxTitle</h4>
                  <p>@page.recBoxBodyText</p>
                </div>
              }else {
     @ReadRss(@page.rssBoxUrl, @page.rssBoxTitle);
              }
            }  
        }    
    @helper ReadRss(string url, string title){
     
    XmlTextReader rssReader = new XmlTextReader(url);

    XmlDocument doc = new XmlDocument();
     
    doc.Load(rssReader);
     
    XmlNodeList rssItems = doc.SelectNodes("//item");


    var maxItems = 4;
    var displayCount = rssItems.Count < maxItems ? rssItems.Count : maxItems;
    <div class="rss-footer-box col-xs-6 col-sm-3">
    <h4>@title</h4>
    @for (int index = 0; index < displayCount; index++)
    {
     var node = rssItems[index];
     
    <a href="@node["link"].InnerText">@node["title"].InnerText</a><br />
    @Convert.ToDateTime(node["pubDate"].InnerText).ToString("d MMMM yyyy")<br /><br />
    }
     </div>
    }
    }

    Thanks alot! 

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Apr 20, 2015 @ 12:04
    Jeroen Breuer
    0

    Hello,

    Doesn't it render anything or do you get an error? Your code has an if statement and a foreach after that so if it doesn't pass the if or there no item to iterate in the foreach it won't render anything. If you debug the code you might see what could be wrong.

    Jeroen

  • Nicolai 48 posts 201 karma points
    Apr 20, 2015 @ 13:05
    Nicolai
    0

    Im sorry, I fixed my problem. It was caused by some invalid RSS feed. Can we close topic?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Apr 20, 2015 @ 13:07
    Jan Skovgaard
    0

    Hi Nicolai

    You can mark it as solved somewhere near the avatars.

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft