Copied to clipboard

Flag this post as spam?

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


  • Streety 358 posts 568 karma points
    Feb 16, 2012 @ 12:24
    Streety
    0

    Trying to pick objects from 2 nodes using IEnumerable<DynamicNode>

    I have a problem.

    I need to pick the latest posts from 2 blogs within my site.

    The problem is I don't fully understand the razor syntax (actually I am struggling).

     

    I need the script to look at the root of the blogs and show the latest 2 postings This work fine if I only want to look into one blog. If I apply the second it duplicates the first blog post and ignores the variables.

    @using System.Linq
    @using System.Xml.Linq
    @using umbraco.MacroEngines
    @using uBlogsy.Common.Extensions
    @using uBlogsy.Common.Helpers
    @using uBlogsy.BusinessLogic
    @{
    const int ITEMS_PER_PAGE = 20; // for testing

    // get item count
    int count = int.Parse(@Parameter.ItemCount);

    IEnumerable<DynamicNode> nodes, nodes2;

    var posts = PostService.Instance.GetPosts(1355);
    var promowatchposts = PostService.Instance.GetPosts(1352);

    nodes = ((IEnumerable<DynamicNode>)posts).Take(count);
    nodes2 = ((IEnumerable<DynamicNode>)promowatchposts).Take(count);

    <div class="uBlogsy_posts_container uBlogsy_bottom_border">

    <h2>Latest Blog1 posts</h2>
    <ul>
    @foreach (DynamicNode n in nodes)
    {
    <li>
    <a href="@n.Url" title="@n.GetProperty("uBlogsyContentTitle").Value">
    <span>@n.GetProperty("uBlogsyPostDate").Value.FormatDateTimeOrdinal("d MMMM yyyy") - @n.GetProperty("uBlogsyContentTitle").Value</span>
    </a>
    </li>
    }
    </ul>



    <h2>Latest Blog2 posts</h2>
    <ul>
    @foreach (DynamicNode n in nodes2)
    {
    <li>
    <a href="@n.Url" title="@n.GetProperty("uBlogsyContentTitle").Value">
    <span>@n.GetProperty("uBlogsyPostDate").Value.FormatDateTimeOrdinal("d MMMM yyyy") - @n.GetProperty("uBlogsyContentTitle").Value</span>
    </a>

    </li>
    }
    </ul>
    </div>
    }

     

    I am not guessing the syntax as var "promowatchposts" is ignored.

    I also tried to break these scripts into 2 separate scripts that returned the same ( 2 lots of the same Blog 1 postings)

    Any Ideas. Thank you.

     

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies