自定义视图对于果园RecentBlogPosts [英] Custom View For RecentBlogPosts in Orchard
问题描述
我一直在寻找和尝试2天更改视图,关于我的主页出现的RecentBlogPosts内容类型。我想显示标题,并从该职位的短语。
I've been searching and trying for 2 days to change the view for the RecentBlogPosts content type that appears on my homepage. I want to display the title and a phrase from the posts.
我设法找到一个视图,显示每个帖子的标题,但我还没有设法找出在模型中的其他部分被命名或如何提取文本。
I have managed to find a view that shows the title for each post, but I haven't managed to figure out what the other parts in the Model are named or how to extract the text.
帮助将不胜AP preciated!
Help will be GREATLY appreciated !
@using Orchard.ContentManagement;
@using Orchard.Core.Routable.Models;
@using Contrib.Hyperlink.Fields;
@{
IEnumerable<object> blogPosts = Model.ContentItems.ContentItems;
}
@if (blogPosts == null || blogPosts.Count() < 1)
{
<p>@T("No posts.")</p>
}
else
{
<div class="content-items">
@foreach (dynamic post in blogPosts)
{
string title = post.Title;
ContentItem item = post.ContentItem;
<div class="blogpost" style="width: 300px; padding-left: 15px; float: left;">
<p class="content-item-summary">@Html.ItemDisplayLink(title, item)</p>
</div>
}
</div>
}
以上code是(主要)由贝特朗·勒罗伊的的博客,为此,我感谢他。
The above code was (mainly) from Bertrand Le Roy's blog, for which I thank him.
推荐答案
该ContentItem是博文内容项,其中包含<一个href="http://orchard.$c$cplex.com/SourceControl/changeset/view/fe55d6737a3e#src/Orchard.Web/Modules/Orchard.Blogs/Models/BlogPostPart.cs"相对=nofollow> BlogPostPart (从Orchard.Blogs.Models命名空间)。所以,你可以使用它的任何属性 - 结帐链接到源$ C $ C我上面提供
The ContentItem is a BlogPost content item, which contains BlogPostPart (from Orchard.Blogs.Models namespace). So you can use any properties it has - checkout the link to the source code I provided above.
这部分有文字属性,它的引擎盖下相应的 BodyPart的(该博文的类型已经附太)返回HTML。 而BTW - 请记住,使用的 @ Html.Raw(part.Text)的显示获取的内容
This part has the Text property, which returns the Html from corresponding BodyPart (which BlogPost type has attached too) under the hood. And btw - Remember to use @Html.Raw(part.Text) to display the fetched content.
还有一件事 - 为使生活更轻松,我宁愿投的迭代对象为 BlogPostPart ,以获得智能感知:
One more thing - for making life easier I'd rather cast that iterated objects to BlogPostPart to get Intellisense:
@foreach (var post in blogPosts.Select(p => ((IContent)p.ContentItem).As<BlogPostPart>()))
{
...
}
心连心
这篇关于自定义视图对于果园RecentBlogPosts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!