Multiple facebook comments in content widget

Dec 1, 2012 at 9:53 AM

Don't know if its a content widget or facebook suite issue...

Anyway, I have successfully added the facebook comments box as a content widget to the blogpost content type.

However on a blog page (with multiple blog posts) the comments are tied to the url of the blog page, so the comment boxes for all blog posts on the page displays the same comments.

Looking at FacebookCommentsBox.cshtml, this looks reasonable, since it contains:


<div class="fb-comments" data-href="@ViewContext.RequestContext.HttpContext.Request.ToUrlString()"

Whats the best way to get the data-href to something unique for the blog post ? (preferably the permalink of the blog post)

Thanks

 

Dec 1, 2012 at 11:37 AM

For now I'd advice you to simply only display comments when in detail display mode. This has better usability too I think as FB comments load slowly.

The problem here is that the widget would have to know what content item it's attached to in order to retrieve its (the parent's) display url. This is possible in multiple ways (I've also implemented such contexting a few times elsewhere). I was going to explain what are the issues with implementing this in a generic way but I found as simple solution one in the meantime :-). I just pushed some modifications, please try it out and let me know what do you think. Here it is what happens:

When building the display shape of the widgets attached to a content item the modified ContentWidgetsPartDriver adds a new property to every items' shape in the Content zone, called ParentContentItem that contains the content item's reference the widget is attached to. Practically this means that all shapes placed in the Content local zone of content items will have this new property and they'll be able to access the parent content item through it.

So in the shape template of FB Comments you could use the following code to display the display url of the parent item:

@Url.ItemDisplayUrl((Orchard.ContentManagement.IContent)Model.ParentContentItem)

You get the idea :-).

Dec 1, 2012 at 9:30 PM

Thanks for the extremely quick response and fix.

I have tried it out, and it works perfectly !

Dec 1, 2012 at 10:59 PM

Glad it worked out for you :-).