1

I'm trying to render the list of blog posts in this layout:

[first post - special summary]
[second post][third post][fourth post]
[pager]

I'm trying to render the first post myself and then loop over the remaining items to render them using the blog post summary template.

A number of questions here:

  1. Is this a good way to pull off the layout I'm trying to achieve or should I start looking into creating a module?
  2. Should I create a summary template for my special first post rendering and how would I go about that?
  3. If I continue down the same path how do I render parts like tags and the postdate?

I have this so far in my theme: Parts.Blogs.BlogPost.List-url-blog.cshtml

@using Orchard.Blogs.Extensions;
@using Orchard.Blogs.Models;
@using Orchard.ContentManagement;
@using Orchard.Utility.Extensions;
@{
    IEnumerable<dynamic> blogPosts = Model.ContentItems;
    Model.ContentItems.Classes.Add("content-items");
    Model.ContentItems.Classes.Add("blog-posts");

    var firstPost = blogPosts.FirstOrDefault();
    //BlogPart blog = (BlogPart)firstPost.Get(typeof(BlogPart));

}
<h1>@firstPost.Title</h1>
by <span>@firstPost.ContentItem.CommonPart.Owner.NormalizedUserName</span>

@* How do i render tags using the tags part template? *@

@Display(firstPost.Tags) 
@Display(firstPost.Parts_Tags_ShowTags)
@Display(firstPost.TagsPart) 
@Display(firstPost.ContentItem.TagsPart)
@Display(firstPost.ContentItem.TagsPart.ContentItem)

@* none of the above work *@

<hr />
<ul class="content-items">
    @foreach (var post in blogPosts.Skip(1))
    {
        <li class="content-item-summary">
            @Display(post)
        </li>
    }
</ul>

Bonus points - Why can't I do something like this:

@Display(blogPosts.Skip(1))

but I can do

@Display(blogPosts)
4

1 回答 1

3

啊,你好。尝试这个:

@using Orchard.Blogs.Extensions;
@using Orchard.Blogs.Models;
@using Orchard.ContentManagement;
@using Orchard.Utility.Extensions;
@{
    IEnumerable<dynamic> blogPosts = Model.ContentItems;
    Model.ContentItems.Classes.Add("content-items");
    Model.ContentItems.Classes.Add("blog-posts");

    var firstPost = blogPosts.FirstOrDefault();
    var otherPosts = blogPosts.Skip(1).ToList();
}
<h1>@firstPost.Title</h1>
by <span>@firstPost.ContentItem.CommonPart.Owner.NormalizedUserName</span>

@Display(New.MyTagShape(Tags: firstPost.ContentItem.TagsPart.CurrentTags))

<hr />
@Display(New.List().AddRange(otherPosts))

然后这是 MyTagShape.cshtml 的代码:

Here are your tags:
<ul>
@foreach (var tag in Model.Tags) {
    <li>@tag.TagName</li>
}
</ul>

在我的机器上工作。但正如我在论坛上所说,您可能想要自定义摘要模板而不是整个列表。

编辑:这是为第一项创建不同模板的方法:http ://weblogs.asp.net/bleroy/archive/2011/05/23/orchard-list-customization-first-item-template.aspx

于 2011-05-13T01:12:50.220 回答