Copied to clipboard

Flag this post as spam?

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


  • Michael 63 posts 211 karma points
    Jun 13, 2012 @ 21:45
    Michael
    0

    RSS feed displaying a specific doctype

    Hi guys

    Been searching the forum and google without result, sorry if I missed a similar post.

    I am new at this razor stuff (more of a design/html/css guy :P), so still a lot of learning to do. I am trying to make a RSS feed which only displays a specific doctype in my news section.

    My site structure looks like this:

    Website
    -Subpage
    ...

    Newssection
    -Year
    --NewsArticle
    --NewsArticle
    -Year
    --NewsArticle

    and so on.

    I have been using the code from the Umbraco Razor RSS recipes: http://umbraco.com/help-and-support/video-tutorials/umbraco-fundamentals/razor-recipes/rss.aspx

    My code looks like this:

    @{
        //Change mime type
        umbraco.library.ChangeContentType("text/xml");   
        
        //Get the domain
        var siteURL = "http://" + Request.Url.Host;
        
        //Get the news area node (only one of these per site)
        var newsAreaNode = Model.NewsArticles.First();
        
        //Get the latest createDate of all news items to use as the RSS feed updateDate
        var RSSFeedPubDate = newsAreaNode.Children.Where("Visible").OrderBy("updateDate desc").First();
    }
    <?xml version="1.0" encoding="UTF-8"?>
    <rss version="2.0"
        xmlns:content="http://purl.org/rss/1.0/modules/content/"
        xmlns:wfw="http://wellformedweb.org/CommentAPI/"
        xmlns:dc="http://purl.org/dc/elements/1.1/"
        xmlns:rssdatehelper="urn:rssdatehelper">
            <channel>
                <title>My first RSS</title>
                <link>@siteURL</link>
                <pubDate>@RSSFeedPubDate.UpdateDate.ToString("r")</pubDate>
                <generator>umbraco</generator>
                <description>This is my first rss feed</description>
                <language>en</language>
                @{
                    foreach (var item in newsAreaNode.Children.Where("Visible"))
                    {
                        <item>
                            <title>@item.Name</title>
                            <link>@item.Url</link>
                            <pubDate>@item.UpdateDate.ToString("r")</pubDate>
                            <guid>@item.Url</guid>
                            <content:encoded><![CDATA[@item.bodyText]]></content:encoded>
                        </item>
                    }
                }
            </channel>
    </rss>

     

    I am guessing i need to modify the var newsAreaNode? I just can't wrap my head around way to do it :(

    Any help/pointers/links are most welcome :)


    /Michael

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jun 13, 2012 @ 22:58
    Tom Fulton
    0

    Hi Michael,

    I think one of these methods should work:

    foreach (var item in newsAreaNode.Children.Where("Visible && NodeTypeAlias=@0", "NewsArticle"))
    foreach (var item in newsAreaNode.NewsArticles.Where("Visible")) 
    // in razor you can use the pluralized version of the NodeTypeAlias to filter children

    Also if you're looking for more Razor examples, check out:

    Cultiv Razor Examples
    Razor DynamicNode Cheat Sheet

    HTH,
    Tom 

     

     

     

     

     

     

     

  • Michael 63 posts 211 karma points
    Jun 18, 2012 @ 14:51
    Michael
    0

    Hi Tom

    Got it working now. Thanks for the pointers ;)

     

    /Michael

  • Darshit 7 posts 50 karma points
    Jan 05, 2013 @ 19:22
    Darshit
    0

    HI I am having same problem!!

     

    my domain http://maceit.visa4u.in

     

    i am creating rss feed for my news and events "http://maceit.visa4u.in/news-and-events.aspx" ..

     

    i am using this razor

     

    @{
        //Change mime type
        umbraco.library.ChangeContentType("text/xml");  
       
        //Get the domain
        var siteURL = "http://" + Request.Url.Host;
       
       
       
        //Get the news area node (only one of these per site)
        var newsAreaNode = Model.NewsAreas.First();
       
       
       
        //Get the latest createDate of all news items to use as the RSS feed updateDate
        var RSSFeedPubDate = newsAreaNode.Children.Where("Visible").OrderBy("updateDate desc").First();
    }
    <?xml version="1.0" encoding="UTF-8"?>
    <rss version="2.0"
        xmlns:content="http://purl.org/rss/1.0/modules/content/"
        xmlns:wfw="http://wellformedweb.org/CommentAPI/"
        xmlns:dc="http://purl.org/dc/elements/1.1/"
        xmlns:rssdatehelper="urn:rssdatehelper">
            <channel>
                <title>MaceIT News RSS Feed</title>
           
                <link>@siteURL</link>
                <pubDate>@RSSFeedPubDate.UpdateDate.ToString("r")</pubDate>
                <generator>MaceIT News Admin Panel</generator>
                <description>Add your description here</description>
                <language>en</language>
                @{
                    foreach (var item in newsAreaNode.Children.Where("Visible && NodeTypeAlias=@0", "NewsArticle"))
                    {
                   
                        <item>
                            <title>@item.Name</title>
                            <link>@item.Url</link>
                            <pubDate>@item.UpdateDate.ToString("r")</pubDate>
                            <guid>@item.Url</guid>
                            <content:encoded><![CDATA[@item.bodyText]]></content:encoded>
                        </item>
                   
                    }
                }
            </channel>
    </rss>

     

    but http://maceit.visa4u.in/RSStest1 while using this getting nothing!!!

     

    please help me!!

  • MikeD 92 posts 112 karma points
    May 01, 2013 @ 17:46
    MikeD
    0

    Not sure if anyone is still paying attention here, but I am having an issue with this script as well.  If I leave the <link> tag in my foreach loop, I get an error saying there is no closing <item> tag.  If I remove the <link> tag everything works like a champ.  It does not matter what is in there, it's the tags themselves apparently.  I tried putting static text and no text, same results.

    Any ideas or assistance would be most appreciated!

  • Andy 7 posts 26 karma points
    Oct 23, 2013 @ 18:00
    Andy
    0

    Just experienced this same issue, looks like <link> is reserved. I was able to use @:<link>@node.url</link> in my loop. 

Please Sign in or register to post replies

Write your reply to:

Draft