This project is read-only.

Overriding Blog Post Shape

Topics: General
Apr 21, 2011 at 5:38 PM

I am looking to override the way a blog post appears and have successfully done this by adding a "Content-BlogPost.Detail.cshtml" file in my Theme/Views directory. The only problem is I then loose my comments rendering. How do I manually invoke the comments template to render at the bottom of my new view?

Apr 21, 2011 at 5:49 PM

What that's doing is overriding the entire Content.cshtml template.

So if you find the original Content.cshtml (from Orchard.Core/Contents/Views) you can copy all the other bits from there (including the @Display comments that render child shapes).

It's best instead of overriding the entire template to just override individual parts of it.

For instance, Parts.Common.Body.cshtml will just override the body area of the post.

You can use the Designer Tools Shape Tracing module to inspect the page and see which bits of the overall shape are rendered by different templates. You can also see which Alternate templates can be used for more specific overrides.

Apr 21, 2011 at 6:43 PM

Also try out, which enables you to move around or completely hide parts and fields.

Apr 22, 2011 at 3:20 PM

Ok thanks. I referred to this page's table but it is a bit confusing. Like you say create a file "Parts.Common.Body.cshtml" to override the post. But won't that override all body rendering for all content types? Would I just need to check the "ContentType" on rendering then?

The documentation table refers to a folder structure as well which is used in conjunction with the file naming? I have it working great for custom content types I create, but the exact rules of the filenaming are not clear to me.


Thanks guys!

Apr 22, 2011 at 3:43 PM

You can override Parts.Common.Body-BlogPost.cshtml to affect just blog posts.

You really need to look at Shape Tracing. It tells you all the alternate template names for a particular shape, and even has a Create button which will immediately create the override in your theme.