Reference library

Article number: 302748

Using posts for page commenting

Posts are extremely flexible, in this page we indicate how they can be used to create a moderated or unmoderated page commenting system. The example in question would be intended to work on an extranet/intranet where the commenting is from a logged in user. It would possible to create a commenting system on a public system but in such cases the comments would be anonymous.

The steps are as follows

  1. Create a post type that will collect all the information you want from your commenters
  2. Check that this can be populated via the createposts web service
  3. Create a form with the same field names as your post type
  4. Create a data island using searchposts that is filtered to show the comments from that page
  5. Add items 3 and 4 to a variable block so their easy to add to any page you want commenting on
  6. Add the variable block to the relevant pages

The above is a simple example, there would also be option via alternative searchposts data islands to provide listing of all page comments or all pages commented on by a specific user.

In more detail:

Create a post type ‘comments’, taking arguments for logged in users etc

commentingviaposts1

These posts can be populated via a web service eg

http://demo2-gt.nhs.beta2.sitekit.net/admin/post/CreatePost.aspx?a=1&posttypeid=45&sitekit_siteid=3192&body=comment1&Name=commentonpage1&peopleID=101748&ID=591685&active=1&rating=&username=ntill  etc

In terms of user rights the relevant user needs to have publish rights for  the asset class in use they also need to have administrator right if the resulting post is going to be immediately approved (via active=1) otherwise the externally added posts will not appear in the output web service till after they’ve been approved in admin

We need to create a form that passes values to the webservice. Each of the form ‘name’ fields needs to be the same as the argument required by the webservice above. As you can see some of the hidden values can be automatically populated by magic words.

commentingviaposts2

An example of the popup for the 'what do you think?' text area. As you can see it's name value is 'body' so that ultimately the value entered into this field will get passed through to the web service as the body argument,. There needs to be matching name value pairs from the form or the URL to match all the required arguments for the web service.

 

In the form properties section for the form above we pass the values to the createpost web service outlined in 2. This is done by ticking the 'Submit to Web Service or other external URL' box to reveal the dialog box shown below. The createpost URL as shown is entered into this.

http://demo2-gt.nhs.beta2.sitekit.net/admin/post/CreatePost.aspx?posttypeID=45&sitekit_siteid=3192&active=1

As you can see some of the fields needed for the createpost web service can be hard-coded into the URL with the remaining ones drawn from whatever the user inputs in the form. Note the 'active=1' as this means that the post addition is not moderated. The web service defaults to moderated.

commentingviaposts3

We can then embed this form in a page using the XML snippet below

<ENQUIRYFORM>
<FORMID>6403</FORMID>
</ENQUIRYFORM>

To get a commenting block as shown below

commentingviaposts4

To then provide output (previously submitted comments) we add a data island using the filtering via the automatically passed in shortcuts ID of that page. That way all the page commenting post are in one location in admin but they are filtered via shortcutID no each page. We add this data island below the form and put it in a variable block so it can be easily added to lots of pages. In the DI below the ID argument is the posttypeID

<ENQUIRYFORM>
        <FORMID>6403</FORMID>
</ENQUIRYFORM>
<h3>Approved comments so far</h3>
<xmlconsumer>
       <xmlsource url="http://helpcms.sitekit.net/Admin/Post/SearchPosts.aspx?ID=45&custom_ID=302748&orderby=startDate%20desc"  allowedParameters="ID,custom_ID,orderby" ></xmlsource>
      <xslsource url="http://helpcms.sitekit.net/2013-layout/xsl/pagecomments.xsl"></xslsource>
</xmlconsumer>

 We could also provide a page/dataisland with all page comments aggregated on it or alternatively all pages commented on by user x.

Related questions