Show Recent Blog Posts in a module other than Blogs.

Topics: Customizing Orchard, Writing modules
Oct 18, 2013 at 12:20 PM
I want to add recent blog posts in a div in my custom added module.
Say i want to add it on my home page in a div.
something like this:
            RECENT BLOG POST</h3>
        <div class="BlogPostBox">

            // Blog's Recent Posts here
            // .......What to code here to return that view ???

I have made a view for that in Orchard.Blogs Module
and referenced Orchard.Blogs in my module.

Action in my Module is something like that:
 public ActionResult BlogPost()
            return new Orchard.Blogs.Controllers.RecentBlogPostController().BlogPostList();
and Action in Orchard.Blogs.Controllers.RecentBlogPostController is:
 public ActionResult BlogPostList()
            return View("../Parts.Blogs.RecentBlogPosts");
Now i want to return this view but i am unable to do.
Oct 18, 2013 at 2:29 PM
Edited Oct 18, 2013 at 2:32 PM
You have not to add a view in Blogs Modules.
Simply use shapes in your module's controller and in the corresponding wiew (in your module), exploit what you have set in the shape.

code sample (totally unrelated)
public ActionResult Index()
            _workContextAccessor.GetContext().Layout.IsPromotionPage = true;
            return new ShapeResult(this, BuildCustomerPromotion2Shape());

        private dynamic BuildCustomerPromotion2Shape(bool isSummary = false, LocalizedString message = null)
            dynamic shape                   = _shapeFactory.CustomerPromotion2();

            var viewModel                   = new CustomerPromotion2ViewModel_Display();
            List<CustomerPromotion2> userPromotions = new List<CustomerPromotion2>();

            int customerId                  = _customerService.GetCurrentCustomerId();

            var customerActivePromotions    = _promotionService.GetCustomerActivePromotions(customerId);
            foreach (var customerActivePromotion in customerActivePromotions.Where(uap => uap != null))
                var urlHelper = new UrlHelper(_workContextAccessor.GetContext().HttpContext.Request.RequestContext);
                var promotionDisplayUrl = urlHelper.ItemDisplayUrl(customerActivePromotion.ContentItem);
                promotionDisplayUrl     = urlHelper.RouteUrl(_orchardServices.ContentManager.GetItemMetadata(customerActivePromotion).DisplayRouteValues);
                if (promotionDisplayUrl.ToLowerInvariant().Contains("/contents/"))//.StartsWith("/contents/"))
                    promotionDisplayUrl = string.Empty;

                //promotionDisplayUrl = urlHelper.RequestContext.HttpContext.Request.ToApplicationRootUrlString() + string.Format("/promotions/view/{0}", customerActivePromotion.Id);
                CustomerPromotion2 userPromotion = new CustomerPromotion2()
                    PromotionPart           = customerActivePromotion,
                    PromotionTitle          = _orchardServices.ContentManager.GetItemMetadata(customerActivePromotion).DisplayText,
                    PromotionDisplayUrl     = promotionDisplayUrl
            viewModel.CustomerPromotion2s   = userPromotions;
            viewModel.Message               = (message==null) ? T(""): message;

            shape.ViewModel                 = viewModel;

            return shape;
@using Datwendo.Commerce.Models;
@using Datwendo.Commerce.ViewModels;

    List<CustomerPromotion2> customerPromotions = Model.ViewModel.CustomerPromotion2s;
    int i = 0;

@using (Html.BeginFormAntiForgeryPost(Url.Action("Add", "CustomerPromotion2", new { area = "Datwendo.Commerce" })))
    <div id="customerPromotionmessage">
        @if (!String.IsNullOrEmpty(Model.ViewModel.Message.Text)) {
            @: <b>@Model.ViewModel.Message</b>
    <div class="promotions">
        <div class="row-fluid">
            <div class="span6">@T("Promotion")</div>
            <div class="span2">@T("Discount")</div>
            <div class="span4"></div>
        @foreach (var customerPromotion in customerPromotions) {
        <div class="row-fluid">
            <div class="span6">
                @if (String.IsNullOrEmpty(customerPromotion.PromotionDisplayUrl)) {
                    // Don't display with a hyperlink
                    if (String.IsNullOrEmpty(customerPromotion.PromotionTitle)) {
                        // Don't display with title, just Promotion Code