obaylis
obaylis

Reputation: 3034

Sharing Orchard CMS blog posts - overriding templates

I'm using Orchard CMS and want to be able to show sharing links (think AddThis.com or Shareaholic.com) to blog posts on a website.

Before I start I realise there is a similar modules already present in the Orchard gallery but a, I couldn't get the module to work and b, I'd like to further my understanding of Orchard.

My thought originally was simply to add a new blog widget layer and to add a new HTML widget that contains the aforementioned sharing code. Trouble with this approach was;

  1. The layer rule would force all of my blog pages to have to be under some common url i.e. using a layer rule of something like the following. Not necessarily a bad thing but something that could be missed when the client publishes a new post.

    url("~/blog*")

  2. The sharing code contains empty html anchor elements that were getting stripped from the html when I saved in the Orchard editor.

I think #2 is down to the template used in my theme. I read a post from Bertrand Le Roy's blog about overriding templates which got me thinking. Can I just override the Orchard blog template and place the sharing code in there directly? Clearly this is less customisable in the future but I'm happy with that. I'm also thinking having fewer layers, moduels, widgets or whatever can't be a bad thing when considering Orchard performance and load times. I'd also now have my sharing icons on every blog post wherever it may be on the site.

Question is what is the view that I should override in this case? I tried editing the blog views in Modules\Orchard.Blogs\Views expecting to see some changes but I got nothing.

What would people suggest as the best way forward?

Upvotes: 1

Views: 880

Answers (1)

Ivan Ferić
Ivan Ferić

Reputation: 4763

The best approach IMHO is to add the code in one of two (or both) templates:

  1. Content-BlogPost.Summary.cshtml when the blog post is shown in a list (you can copy the code from /Core/Contents/Views/Content.Summary.cshtml) and
  2. Content-BlogPost.Detail.cshtml when the blog post is shown in a separate page (you can copy the code from /Core/Contents/Views/Content.cshtml)

Upvotes: 2

Related Questions