Copied to clipboard

Flag this post as spam?

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


  • Fran Hoey 15 posts 27 karma points
    Apr 23, 2012 @ 12:25
    Fran Hoey
    0

    Umb 5 - Display Latest News

    I'm trying to display the latest new article on my home page using Umbraco 5.0. 

    The parent new item is passed as a macro parameter called "news" and I successfully get the node by:

    string newsFolderId = Model.MacroParameters.news;
    var newsFolderHiveId = new Umbraco.Framework.HiveId(newsFolderId);
    var newsItemParent = Hive.Content.Where(content => content.Id == newsFolderHiveId).FirstOrDefault();
    var newsItem = newsItemParent.ChildContent().FirstOrDefault();

    Looking at newsItem.Name etc, I've got the node I want, but when I try to access the fields I the error "Sorry, an error occurred while processing your request." 

    For example, I've tried the following to get bodyText field which contains the main HTML of the article

    newsItem.bodyText
    newsItem.Field("bodyText")

     

    What am I missing??

    Thanks,
    Fran

  • LordToro 9 posts 29 karma points
    Apr 25, 2012 @ 11:18
    LordToro
    0

    I think you should to make sure by checking number of ChildContent should have at least 1 node and let try get bodyText "asDynamic" like this:

    if(newsItemParent.ChildContent().Count() > 1)
    {

     

    Content newsItem = newsItemParent.ChildContent().FirstOrDefault();
     newsItem.AsDynamic().bodyText;

     

    }

    Please let me know if it work :)

  • Fran Hoey 15 posts 27 karma points
    Apr 25, 2012 @ 11:49
    Fran Hoey
    0

    That did it!

    Thank you

Please Sign in or register to post replies

Write your reply to:

Draft