Copied to clipboard

Flag this post as spam?

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

  • Owain Williams 408 posts 1213 karma points MVP 3x c-trib
    Aug 29, 2018 @ 19:16
    Owain Williams

    How would you build this news page?

    I'm looking for some help / guidance on how you would recommend building a news / search page.

    In the backoffice I am using nested content and I can select 3 different news article types. News, Videos, Download. enter image description here

    I'm thinking I can create my news page with the help of Examine. But that's as far as I have managed to get.

    I need to show the top 5 featured articles, which are set by a tick box on each article. The first featured article shows a hero image then the following 4 articles only show the article title and a short summary.

    Below all of this, I'll list all the articles in date order with two drop down lists to allow for filtering the articles by type and/or category.

    I started working on this but I was putting all my logic in the view but I think I should be moving stuff out to a controller. But I'm not clear on how to do this.

    I'm using Models Builder too.

    I know there is a lot of things to cover here but I'd appreciate any help.

    Thanks, Owain.

  • Sotiris Filippidis 257 posts 1287 karma points
    Aug 29, 2018 @ 19:28
    Sotiris Filippidis

    Let me try to start things up, although I won't cover 100% of your questions.

    Personally, I'd favor an MNTP on the root news page which would be used to select the featured articles than having to check boxes (which I could easily lose count of).

    I agree with you - a controller would be a good way to offload logic from the view. I would create a controller that would populate a collection of custom objects- the ViewModel, if you will, which would have only the properties that would need to be displayed, along with an enum showing what actual type of item it is (video/download/article). On the view, I would see what the enum is and act accordingly. Setting the hero image would also be easy that way if you used ImageCropper either on the view's side or by setting some special property in the viewmodel.

    The two drop down lists are tricky - best way to implement those in my opinion is to populate them via controller actions (and cache the result sets) and then use ajax to call the controller that will render a view underneath. I could find some samples if you need some.

    Finally, don't forget paging! (Or endless load!)

    I know this is too little, but I hope it'll be a starting point for more.

  • David Peck 589 posts 1557 karma points c-trib
    Aug 29, 2018 @ 19:37
    David Peck

    I'd stick with the featured tick box, set via a composition, on the data type.

    To get the results I'd do two examine searches. One for featured items, and the other not, de-dupping.

    Controllers are easy, just follow the documentation here:

  • Owain Williams 408 posts 1213 karma points MVP 3x c-trib
    Aug 29, 2018 @ 21:15
    Owain Williams

    I'm keeping the feature checkbox because I don't need to keep track of them. I will only show the latest 5 for example.

    The key word there for me to look in to is ViewModel. I've been struggling to work out how I get the data from my controller to the view and I'm thinking this might be key.

    I'll read up about this more tomorrow. I'm thinking this might be a good place to start reading -

    Thanks for the Controller link David, I have used this and it's got me part of the way I think.

    I think I'll start one bit at a time, getting the top 5 features articles out of my Nested Content. Then build from there. I might be trying to do everything at once and getting confused.

    Any other points are welcome - thanks for the help so far.


  • David Peck 589 posts 1557 karma points c-trib
    Aug 29, 2018 @ 21:47
    David Peck

    Create a class called NewsListingViewModel which inherits from RenderModel<NewsListing> where NewsListing is the model generated for your listing page.

    Your Controller would be called NewsListingController and might would return a new instance of NewsListingViewModel. You can then add your own custom properties to NewsListingViewModel such as your list of news articles.

    If you set your template to @inherits UmbracoViewPage<NewsListingViewModel> then you'll be able to access your custom properties through Model.MyCustomProperty and your NewsListing through Model.Content.


    public class NewsListingViewModel : RenderModel<NewsListing>{
        public NewsListingViewModel (NewsListing model) : base(model) {}
        public IList<IPublishedContent> NewsArticles { get; set; }

    ---View Model

    public class NewsListingController : RenderMvcController {
        public override ActionResult Index(NewsListing model)
            var viewModel = new NewsListingViewModel(model){
                //GetNewsArticles gets your articles from Examine and the content cache
                NewsArticles = GetNewsArticles() 
            // Do some stuff here, then return the base method
            return CurrentTemplate(model);


    @inhertits UmbracoViewPage<NewsListingViewModel>
    @foreach(var article in Model.NewsArticles ){
  • Jamie Townsend 21 posts 159 karma points c-trib
    Aug 29, 2018 @ 21:25
    Jamie Townsend

    Have you considered pagination, loading of the rest of the news articles? I assume there could be quite a few?

    I’ve built similar this week, actually a blog but same difference. I used Ajax to a surface controller to get a partial view passing in a view model of x records and then using Ajax to append to the bottom of the blog posts div when a user clicks ‘load more’... happy to share what I’ve got tomorrow, it’s still a work in progress but seems to work well.

  • Marcin Zajkowski 97 posts 558 karma points MVP 3x c-trib
    Aug 30, 2018 @ 08:53
    Marcin Zajkowski

    Hey Owain,

    do I understand it correctly that you need to scan through the all news to get the 5 featured articles? If so, it's definitely not the best approach.

    If you're (or any editor is) in the control of the featured articles (they are not e.g. last 5 published articles etc.), the best way would be to set a MNTP in the page where the featured news will be displayed and select / manage them there. You'll have them in a single place, already selected and ready to be rendered.

    In terms of listing page and search functionality, you can definitely use Examine for it. It'll be especially helpful when you'll have a lot of articles and be willing to filter them for example. You can use the default search provider and narrow the search by using documenttype filters and create some services / controllers where you'll consume the received data in.

    David's explanation of controller's usage is great, you should start from it and scan through those pages to get more feeling about the implementation:

    1. Custom routes (hijacks):
    2. Examine (in general):
    3. Awesome search example / package - ezSearch:

    I did a really base implementation of listing page without any controllers and just based on the content tree on my blog too, but this code is nothing what I would be proud of showing :)

  • Owain Williams 408 posts 1213 karma points MVP 3x c-trib
    Aug 30, 2018 @ 09:14
    Owain Williams

    Thanks everyone - lots of great feedback.

    I'll rethink the featured articles process and put a Mutlinode Tree picker on instead.

    I'll also read all the articles you've suggested. Thanks! All really helpful. Just struggling a bit with this and feeling the pressure to get the job done! :)


Please Sign in or register to post replies

Write your reply to: