Customizing how content is rendered

Topics: Writing themes
Aug 30, 2014 at 8:31 PM

I need help. I am currently creating my own theme.. Everything works fine except I cannot figure out how to customize displayed content. In articles Orchard automatically shows every fields, parts etc.. When I was using Umbraco I had complete control what will be display....

With Orchard even after couple of hours I cannot achieve my desired result :/ I have also watched Orchard Fundamentals on Pluralsight.

Is there somewhere really detailed how-to for content rendering? When I add some fields for example to my Blog Post in Content Definition how can I access it via Model in Views?

Thanks for any help.
Aug 31, 2014 at 8:06 PM
Nobody? :/

I try to explain my problem again.

This is currently my code for displaying blog posts in list:
 <ul class="content-items">
    @foreach (dynamic post in blogPosts) {
        string title = post.Title;
        ContentItem item = post.ContentItem;
        <li class="content-item-summary">
            @Html.ItemDisplayLink(title, item)
But I would like to display more than just link to open new page. However things like @post.Body or @post.Tags don't work. How can I access blog posts properties and/or my added fields in similar fashion to post.Title?
Sep 2, 2014 at 4:28 PM
Edited Sep 2, 2014 at 4:34 PM
You can access to a Part from the ContentItem like this :
BodyPart body = post.As<BodyPart>();
// And then to the properties of the part :
But I don't know if it is the best way to do what you want.
Sep 2, 2014 at 4:41 PM
A syntax like this could work for the tags :
Sep 2, 2014 at 5:39 PM
Thanks, I'll try this way and see if it works. Can I access my fields in similar fashion? I would like to display image alongside title and excerpt in my blog posts list. I have it added as content media field and it is automatically displayed in full blog post view (however I don't want it there :D)
Sep 2, 2014 at 8:03 PM
Just tried. First option (post.As<BodyPart>) throws compilation error, it does not know the type BodyPart. Second option does not outputs any tags even though I have them set in my posts.
Sep 3, 2014 at 5:56 AM
Import the namespace for the Body part : @using Orchard.Core.Common.Models

Try @Display(post.Tags) for the tags

See an example here to use a MediaField :
Sep 3, 2014 at 9:03 PM
Ouch, that mistake with namespace was stupid, but now BodyPart just throws null exception.

I copied the example code, added new image field with same name ("BlogPostImage") but it does not show neither it shows Tags from @Display(Model.Tags) as shown in example.

@Display(post.Tags) does not output anything.

This is how you can access anything in Umbraco:
And this is Orchard:
Maybe I am just stupid, but it seems just painful to me...
Sep 4, 2014 at 1:06 PM
Hi, consider enabling ShapeTracing, it will help you a lot with the Model as well as with alternates templates
Sep 4, 2014 at 5:49 PM
Of course I am using ShapeTracking from the begining.. But even though if ti shows me Model and its properties I still cannot access them in my code.

Now I have partly customized recent blog posts list (thanks to source code from the Internet) but of course this same approach does not work for projection list.
Sep 4, 2014 at 8:01 PM
Okay, after at least 10 hours of trying I can finally declare a victory over Orchard in the terms of shapes rendering and customization.