1
votes

I'm new to Orchard and have watched both the Pluralsight "Orchard Fundamentals" and "Advanced Orchard" tutorials. Its a great platform, but I'm having a hard time wrapping my head around a couple of things.

I'd like to create a blog showcase banner on the home page only that rotates blog posts on the site. I have the HTML sliced up and functioning on an HTML template. The banner looks like this:

http://arerra.com/news-slideshow.jpg

So far I have done the following:

  1. I've created a Blog called "Articles" and have placed a single post in there for testing.

  2. Added a Layer called "ArticleList" where I have placed a Widget for "Recent Blog Posts"

  3. I've created a custom layout for the home page called "Layout-Url-HomePage.cshtml" in my theme.

  4. In my Theme "Views" folder, I have created a file called "Widget.Wrapper.cshtml" with only @Display(Model.Child) in it to remove the <article><header/><footer /><article> tags globally from the widgets.

  5. Added a file in "Views > Parts > Blogs.RecentBlogPosts.cshtml" to control the layout of my shape. The code is the following:

    @using Orchard.ContentManagement;
    @{
        IEnumerable<object> blogPosts = Model.ContentItems.ContentItems;
    }
    
    @if (blogPosts != null) {
    <div class="container news-slider">
        <ul class="slide-images">
            @foreach (dynamic post in blogPosts) {
                 string title = post.Title;
                 ContentItem item = post.ContentItem;
    
                 <img src="/Themes/MountainWestHoops/Content/img/placeholder-700x380.jpg" alt="@title" class="active" />
            }
        </ul>
    
        @foreach (dynamic post in blogPosts) {
            string title = post.Title;
            string body = post.Body;
            ContentItem item = post.ContentItem;
    
            <div class="featured-story threeD active">
                <h1>@title</h1>
                <p>@body @Html.ItemDisplayLink("READ MORE", item)</p>
            </div>
        }
    
        <aside>
            <ul class="tabs">
                @foreach (dynamic post in blogPosts) {
                    string title = post.Title;
                    string url = post.Url;
                    ContentItem item = post.ContentItem;
    
                    <li><a href="@url"><h3>@title</h3></a></li>
                }
            </ul>
    
            <div class="ad-three-day-trial">
                <a href=""><img src="/Themes/Content/img/placeholder-260x190.gif" /></a>
            </div>
        </aside>
    </div>
    }    
    
  6. My HTML is rendering properly, but none of the values that I have specified are showing up.

  7. I am using the "Shape Tracer" module to see what template is being used. What is funny, is that the @Html.ItemDisplayLink("READ MORE", item) is rendering the article's URL, and if I replace the "READ MORE" with the string title, the title renders properly.

What am I doing wrong here that is causing strings to not display? Am I missing a larger point and misunderstanding the fundamentals? The tutorials seems to say that you can simply move around parts, but in this case, I need to have very specific markup for this slider to work.

1

1 Answers

1
votes

Seems like your source was http://weblogs.asp.net/bleroy/archive/2011/03/27/taking-over-list-rendering-in-orchard.aspx

That is a rather old post, and the way the title is handled has changed since then.

The DisplayLink works because the only correct property here is post.ContentItem, which is what that API takes. post.Title and post.Body on the other hand are very likely null, which is why you see nothing. To access the title, you can use post.ContentItem.TitlePart.Title and to get the body, post.ContentItem.BodyPart.Text.