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.
@{ //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 :(
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:
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>
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!
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
Hi Michael,
I think one of these methods should work:
Also if you're looking for more Razor examples, check out:
- Cultiv Razor Examples
- Razor DynamicNode Cheat Sheet
HTH,
Tom
Hi Tom
Got it working now. Thanks for the pointers ;)
/Michael
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!!
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!
Just experienced this same issue, looks like <link> is reserved. I was able to use @:<link>@node.url</link> in my loop.
is working on a reply...