Overriding Blog Post Shape

Topics: General
Editor
Apr 21, 2011 at 4: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 4: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.

Coordinator
Apr 21, 2011 at 5:43 PM

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

Editor
Apr 22, 2011 at 2:20 PM

Ok thanks. I referred to this page's table http://www.orchardproject.net/docs/Accessing-and-rendering-shapes.ashx 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 2: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.