This page is part of a series on my blog engine called BlogMatrix. The full series is listed below. Enjoy.
As a blogger it's great to be able to share your thoughts with the universe. It's even better when the universe talks back! On a serious note blog comments are a great way to get feedback on your ideas and get some robust discussion going. This is how I set them up, for my blog engine, using Disqus.
I'm assuming you know what Disqus is, if not go and read about it here. Needless to say it's an awesome tool to build a community around your blog. It's also dirt easy to get setup on your blog as it's just a javascript embed code.
As I said it's dirt easy getting setup with Disqus.
This is not a detailed post on how to get Disqus up and running so if you have problems getting it setup Google is your friend :)
The easiest way to use the Disqus javascript embed code would be to put it in my main Layout file layouts/_SiteLayout.cshtml
. However this would result in a comments
section appearing on every page of my site. Not exactly what I want!
Instead I created a new Layout file layouts/_BlogLayout.cshtml
which contained the following:
@{ Layout = '~/layouts/_SiteLayout.cshtml'; } @RenderBody() @RenderPage('/partials/_SocialMedia.cshtml') @if(Page.ShowComments == true) { @RenderPage('/partials/_Disqus.cshtml') };
The key line in the code listing above is the Page.ShowComments == true
if statement. The /partials/_Disqus.cshtml
file simply contains the Disqus javascript embed code
and isn't anything really special.
Each blog post has a configuration section where the Layout file can be specified and any other values set. This is an example of the configuration section for this blog post. You'll notice the
new layout file layouts/_BlogLayout.cshtml
is used on the first line and the Page.ShowComments value being set on the last line:
@{ Layout = '~/layouts/_BlogLayout.cshtml'; // 00017.json var metadata = PostMetaData.GetPostMetaData(Server.MapPath('~/_postmetadata/00017.json')); Page.Title = metadata.title; Page.Meta_Description = metadata.meta_description; Page.ShowComments = true; };
By setting up my blog posts with a separate Layout file I'm able to maintain control over which pages have comments and which don't. That's one of the beauties of rolling your own custom blog engine. You can do whatever you want :)
But most importantly by using Disqus I'm able to get discussions up and running extremely quickly without having to write any serious code.
So send me a quick comment below!