I am new to this and need help urgently. I am creating a blog and I need to display the 5 latest posts on the home page. I want to select the posts in a surface controller and pass them as model to a razor partial view where I output the blog description, title, thumbnail sized image and link to the blog post.
I have been able to do this successfully to output what I need:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
var firstTypedContentAtRoot = Umbraco.TypedContentAtRoot().FirstOrDefault();
But when I try to get posts from surface controller using content service, I can only get a list of type Content/IContent, which I am then struggling to output on the partial view. In particular the image because I only seem to be able to output an image when I use:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
And if I use this then I can't also pass in a model from the surface controller(?)
My code in the surface controller looks like this and returns a partial view:
DonĀ“t know how long you are into the process with your blog, but perhaps, it could be an idea to see if you could use one of the Umbraco blog packages, depending on which Umbraco version your are using.
And there are also the uBlogsy package http://our.umbraco.org/projects/starter-kits/ublogsy, which can be use with Umbraco 7, and older version of Umbraco. The uBlogsy have been the most recommend blog package through time. before the Articulate blog package and SmartBlog package was made.
So as you can see there are some options running a blog on our Umbraco website, or your clients website. So perhaps you could look at the featues that these blog packages can offer, and see if this could be an option to use one of the blog packages instead of creatingyour own blog.
Thanks for your reply. I have to create my own as part of a test and I don't have too much time to look around or learn from scratch. Of course I have now realised that if I can just get a URL to the image from media picker then I can display it without using umbraco dynamic media so I'm working on this and creating my own types to pass in as the model. Appreciate your response though and if anyone has any thoughts on whether this is the best way to proceed, I would love to hear them.
Help to Create Dynamic Blog Listing
Hi,
I am new to this and need help urgently. I am creating a blog and I need to display the 5 latest posts on the home page. I want to select the posts in a surface controller and pass them as model to a razor partial view where I output the blog description, title, thumbnail sized image and link to the blog post.
I have been able to do this successfully to output what I need:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
var firstTypedContentAtRoot = Umbraco.TypedContentAtRoot().FirstOrDefault();
IEnumerable<IPublishedContent> posts = firstTypedContentAtRoot.Descendants(3);
}
<h4>Our Latest Blog Posts</h4>
@foreach (IPublishedContent post in posts)
{
<div style="display: inline-block; width: 20%; padding: 2%; vertical-align: top;margin-top:0px;">
<div>
<a href="@post.Url">@post.Name</a>
</div>
@if (post.HasValue("imagePicker"))
{
var dynamicMediaItem = Umbraco.Media(post.GetPropertyValue("imagePicker"));
<img src="@dynamicMediaItem.umbracoFile" alt="@dynamicMediaItem.Name" style="float: left;border: 0;width: 45%;margin-right:5px;margin-bottom:5px;" />
}
@if (post.HasValue("shortDescription"))
{
string blurb = post.GetPropertyValue("shortDescription").ToString();
<p>@blurb</p>
}
<div style="clear:both"></div>
</div>
}
But when I try to get posts from surface controller using content service, I can only get a list of type Content/IContent, which I am then struggling to output on the partial view. In particular the image because I only seem to be able to output an image when I use:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
And if I use this then I can't also pass in a model from the surface controller(?)
My code in the surface controller looks like this and returns a partial view:
IContentTypeService contentTypeService = ApplicationContext.Current.Services.ContentTypeService;
IContentType mytype = contentTypeService.GetContentType("BlogPage");
// get all content by type
IContentService contentService = ApplicationContext.Current.Services.ContentService;
IEnumerable<IContent> items = contentService.GetContentOfContentType(mytype.Id);
I am seriously confused and possibly looking in the wrong direction. Please can anyone help me or point me in the right direction. Many thanks.
Karen
Hi Karen and welcome to our,
DonĀ“t know how long you are into the process with your blog, but perhaps, it could be an idea to see if you could use one of the Umbraco blog packages, depending on which Umbraco version your are using.
Perhaps the blog packages can cover your or your client's needs, if you are using the Umbraco 7, you could take a look at the Articulate package http://our.umbraco.org/projects/starter-kits/articulate or the SmartBlog http://our.umbraco.org/projects/starter-kits/smart-blog
And there are also the uBlogsy package http://our.umbraco.org/projects/starter-kits/ublogsy, which can be use with Umbraco 7, and older version of Umbraco. The uBlogsy have been the most recommend blog package through time. before the Articulate blog package and SmartBlog package was made.
So as you can see there are some options running a blog on our Umbraco website, or your clients website. So perhaps you could look at the featues that these blog packages can offer, and see if this could be an option to use one of the blog packages instead of creating your own blog.
Hope this heps,
/Dennis
Hi Dennis,
Thanks for your reply. I have to create my own as part of a test and I don't have too much time to look around or learn from scratch. Of course I have now realised that if I can just get a URL to the image from media picker then I can display it without using umbraco dynamic media so I'm working on this and creating my own types to pass in as the model. Appreciate your response though and if anyone has any thoughts on whether this is the best way to proceed, I would love to hear them.
Thanks,
Karen
is working on a reply...