A friend gave me a hand with this bit. Together, we've added:
This gave me a completed Razor function of:
public static XName XML_LINK = XName.Get("link", "http://www.w3.org/2005/Atom");
... to the top of the function, and:var althref = (from altVal in entry.Elements(XML_LINK) where (string)altVal.Attribute("rel") == "alternate" select altVal.Attribute("href").Value).FirstOrDefault();
... within the @foreach to get a value @althref , to insert into the <a href="">.This gave me a completed Razor function of:
@inherits RazorFunction
@functions {
public override string FunctionDescription
{
get { return "Create a gallery of images from a Picasa album RSS feed."; }
}
[FunctionParameter]
public string RssUrl { get; set; }
public int AlbumCount { get; set; }
private static readonly XName XML_TITLE_ENTRY = XName.Get("title", "http://www.w3.org/2005/Atom");
private static readonly XName XML_MEDIAGROUP_ENTRY = XName.Get("group", "http://search.yahoo.com/mrss/");
public static readonly XName XML_CONTENT_MEDIAGROUP = XName.Get("content", "http://search.yahoo.com/mrss/");
public static readonly XName XML_THUMBNAIL_MEDIAGROUP = XName.Get("thumbnail", "http://search.yahoo.com/mrss/");
public static XName XML_ENTRY = XName.Get("entry", "http://www.w3.org/2005/Atom");
public static XName XML_LINK = XName.Get("link", "http://www.w3.org/2005/Atom");
}
@{
var feed = XDocument.Load(RssUrl).Root;
var entries = feed.Elements(XML_ENTRY).Take(AlbumCount).ToList();
}
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://www.composite.net/ns/function/1.0">
<head>
</head>
<body>
<p>
@foreach (var entry in entries)
{
var media = entry.Element(XML_MEDIAGROUP_ENTRY);
var althref = (from altVal in entry.Elements(XML_LINK) where (string)altVal.Attribute("rel") == "alternate" select altVal.Attribute("href").Value).FirstOrDefault();
if (media != null)
{
var imgSrc = media.Element(XML_THUMBNAIL_MEDIAGROUP).Attribute("url").Value;
<a href="@althref"><img src="@imgSrc" alt="@entry.Element(XML_TITLE_ENTRY).Value" class="photogalleryicon"/></a>
}
}
</p>
</body>
</html>
For the caching, I'm wrapping this with Composite.Utils.Caching.PageObjectCache , but was wondering if it's possible to include caching code within the Razor function instead. Answers on a postcard please?