13

I would like to get a list of news items from the Broker in DD4T. I created a Controller to query the Broker and build a list of items using my own Model. The View iterates over the list and deploys the news items.

However, I would like Authors to be able to control the placement of this list on the Page with a Component Template / View.

How could I use a normal View / CT and connect it to my custom Broker query?

2 Answers 2

16

If you have a View for your Component you could do it the .NET MVC way, by hooking up to the Controller/Action you already created by placing @Html.Action("YourNewsActionMethod", "News") in your razor view for the Component. This will call the "YourNewsActionMethod" on your class called NewsController.

11

You can also use the metadata in the Component Template to override the default component controller/action and provider you own.

If you custom action provides a parameter of type IComponentPresentation then DD4T will take care of passing the ComponentPresentation object to you action:

// Use "Index" in the override action field in the component template
public ActionResult Index(IComponentPresentation componentPresentation)
{
    // Your custom logic to get news items
    // yourNewsModel = GetMyNewsModel();
    return View(yourNewsModel);
}

This way you have a Component Template that your editors can use in on their pages and assuming your page template doesn't have any restricting logic, it would be rendered in the order corresponding to the Component Presentation list.

Cheers

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.