Hi guys, I have a comments form build with Contour and I display comments using xslt for-each. I'd like my users to be able to respond to specific comment. So, I need clues on how to do that.
I need to displays responses under the specified comment :
You'll need to link a comment to a parent comment in this case, think easiest would be to use a hidden fieldtype and then set the value of this to the comment record guid. Once you have the relationship you should be able to output them in the way you want
Hi Tim, thank you for your help! Now, how do I use the hidden fieldtype? I understand that I need to add a "reply" link for each comment. This link will pass the "parent id" to the hidden field, but how?
you need to set a form with contour with an hidden field with [@recordid] as default value. So in your xslt you can display each comment with an empty field(parentid in my case) and within this loop you do another loop who check if the current record id as answer and display them.
The last p is where I handle answers. If someone click on the link "Answer", it pass the parameter recordid of the current comment as querystring so it is added in the hidden field. So, it creates answers to the main comment.
<p> Le <xsl:value-of select="umbraco.library:LongDate(created)"/>, <b><xsl:value-of select="./fields/nom//value"/></b> a dit :<br/> <cite style="margin-left:3px;"><xsl:value-of select="umbraco.library:Replace(./fields/message//value,'
','\r\n')" disable-output-escaping="yes" /></cite> </p>
Simon, I was able to cobble somthing together that works. I used the suggestion offered by Tim. I added hidden fields to the form that contain the "parent" comment record ids. I use record storage and linq to retrieve the records and loop through each level of comments by the corresponding id. I am sure there is a better way to do this, but below is some of the code:
<ol id="comments" class="comments">
@{
Umbraco.Forms.Data.Storage.RecordStorage rs = new Umbraco.Forms.Data.Storage.RecordStorage();
Guid formGuidGuid = new Guid("e33fea94-e05c-4aea-81b6-3d8aa21f6840");
var records = rs.GetAllRecords(formGuidGuid).OrderBy(x => x.Created).ThenBy(y => y.GetRecordField("recordid").Values[0]).ThenBy(z => z.GetRecordField("pid2").Values[0]).ThenBy(z => z.GetRecordField("pid3").Values[0]);
var recordID = "";
var recordID1 = "";
var parentID = "";
var recordID2 = "";
var recordID3 = "";
var recordID4 = "";
var recordID5 = "";
var level = "";
var endorseCount = "";
foreach (Umbraco.Forms.Core.Record rec in records)
var subrecs0 = from r0 in records where (r0.GetRecordField("recordID").ValuesAsString() == recordID && r0.GetRecordField("lvl").ValuesAsString() == "0") select r0;
foreach (Umbraco.Forms.Core.Record rec0 in subrecs0)
<span class="glyphicon glyphicon-star-empty small commentfunction"></span><a href="/governance/Endorse?recordid=@recordID" class="vote-up" title="Endorse"> Endorse</a>
<span class="glyphicon glyphicon-share-alt small commentfunction"></span><a href="?parentrecordid=@recordID&pId2=@parentID&pId3=0&pId4=0&lvl=1#contour_form_Comment"> Reply</a>
<span class="glyphicon glyphicon-warning-sign small commentfunction"></span><a href="/governance/report-a-comment?parentrecordid=@recordID"> Report abuse</a>
</p>
</li>
//level 1
var subrecs1 = from r1 in records where (r1.GetRecordField("pid2").ValuesAsString() == parentID && r1.GetRecordField("lvl").ValuesAsString() == "1") select r1;
foreach (Umbraco.Forms.Core.Record rec1 in subrecs1)
Respond to comment
Hi guys, I have a comments form build with Contour and I display comments using xslt for-each. I'd like my users to be able to respond to specific comment. So, I need clues on how to do that.
I need to displays responses under the specified comment :
- comment 1
- comment 2
- reponse to comment 2
- other reponse to comment 2
- comment 3
Thank you for your help!
Comment author was deleted
Well,
You'll need to link a comment to a parent comment in this case, think easiest would be to use a hidden fieldtype and then set the value of this to the comment record guid. Once you have the relationship you should be able to output them in the way you want
Hi Tim, thank you for your help! Now, how do I use the hidden fieldtype? I understand that I need to add a "reply" link for each comment. This link will pass the "parent id" to the hidden field, but how?
Ok, after some searches : set defaultvalue to [@recordid] and it saves the questry string
Hi both,
i am a fresher developer in umbarco,so can u plz tell me the whole step to create comment form witch Profiterole told..
Thanks.
Hi Jay,
you need to set a form with contour with an hidden field with [@recordid] as default value. So in your xslt you can display each comment with an empty field(parentid in my case) and within this loop you do another loop who check if the current record id as answer and display them.
So, it might look like this :
and then :
The last p is where I handle answers. If someone click on the link "Answer", it pass the parameter recordid of the current comment as querystring so it is added in the hidden field. So, it creates answers to the main comment.
I hope it'll help you!
hi Profiterole,
i've tried your code bt it still gives me error on:
if possible then please give me brief description to start with scratch.
Thanks.
Hi, the showcomments template is the second part of my code. Here's my whole xslt (with french variables). Take a look at this :
Thank you Profiterole,
i'll try it.
again thanx.
Reviving an old thread.
I need to do this in version 7. Has anyone done this using Razor syntax?
Robert
Ditto - how did you get on Robert?
Simon, I was able to cobble somthing together that works. I used the suggestion offered by Tim. I added hidden fields to the form that contain the "parent" comment record ids. I use record storage and linq to retrieve the records and loop through each level of comments by the corresponding id. I am sure there is a better way to do this, but below is some of the code:
<ol id="comments" class="comments">
@{
Umbraco.Forms.Data.Storage.RecordStorage rs = new Umbraco.Forms.Data.Storage.RecordStorage();
Guid formGuidGuid = new Guid("e33fea94-e05c-4aea-81b6-3d8aa21f6840");
var records = rs.GetAllRecords(formGuidGuid).OrderBy(x => x.Created).ThenBy(y => y.GetRecordField("recordid").Values[0]).ThenBy(z => z.GetRecordField("pid2").Values[0]).ThenBy(z => z.GetRecordField("pid3").Values[0]);
var recordID = "";
var recordID1 = "";
var parentID = "";
var recordID2 = "";
var recordID3 = "";
var recordID4 = "";
var recordID5 = "";
var level = "";
var endorseCount = "";
foreach (Umbraco.Forms.Core.Record rec in records)
{
if (rec.UmbracoPageId == @Model.id)
{
recordID = rec.Id.ToString();
parentID = rec.GetRecordField("recordid").ValuesAsString();
level = rec.GetRecordField("lvl").ValuesAsString();
endorseCount = rec.GetRecordField("endorseCount").ValuesAsString();
// Level 0
var subrecs0 = from r0 in records where (r0.GetRecordField("recordID").ValuesAsString() == recordID && r0.GetRecordField("lvl").ValuesAsString() == "0") select r0;
foreach (Umbraco.Forms.Core.Record rec0 in subrecs0)
{
<li>
<div>
<span class="medium green">
@rec0.GetRecordField("First name:").Values[0]
@rec0.GetRecordField("Last name:").Values[0] </span>
@if (string.IsNullOrEmpty(@rec0.GetRecordField("Organization:").Values[0].ToString()))
{
<span class="medium green"></span>
}
else
{
<span class="medium green">- @rec0.GetRecordField("Organization:").Values[0] -</span>
}
<span class="light green">wrote on @rec0.Created.ToString("MMMM dd yyy") at
@rec0.Created.ToString("HH:mm tt") </span>
</div>
<div>@rec0.GetRecordField("Comment:").Values[0] </div>
<p class="commentfunctions">
<span class="glyphicon glyphicon-star small"></span> @endorseCount Endorsements
<span class="glyphicon glyphicon-star-empty small commentfunction"></span><a href="/governance/Endorse?recordid=@recordID" class="vote-up" title="Endorse"> Endorse</a>
<span class="glyphicon glyphicon-share-alt small commentfunction"></span><a href="?parentrecordid=@recordID&pId2=@parentID&pId3=0&pId4=0&lvl=1#contour_form_Comment"> Reply</a>
<span class="glyphicon glyphicon-warning-sign small commentfunction"></span><a href="/governance/report-a-comment?parentrecordid=@recordID"> Report abuse</a>
</p>
</li>
//level 1
var subrecs1 = from r1 in records where (r1.GetRecordField("pid2").ValuesAsString() == parentID && r1.GetRecordField("lvl").ValuesAsString() == "1") select r1;
foreach (Umbraco.Forms.Core.Record rec1 in subrecs1)
{
recordID2 = rec1.GetRecordField("pid2").ValuesAsString();
recordID3 = rec1.Id.ToString();
endorseCount = rec1.GetRecordField("endorseCount").ValuesAsString();
<li style="padding-left: 2em;">
<div>
<span class="medium green">
@rec1.GetRecordField("First name:").Values[0]
@rec1.GetRecordField("Last name:").Values[0] </span>
@if (string.IsNullOrEmpty(@rec1.GetRecordField("Organization:").Values[0].ToString()))
{
<span class="medium green"></span>
}
else
{
<span class="medium green">- @rec1.GetRecordField("Organization:").Values[0] -</span>
}
<span class="light green">wrote on @rec1.Created.ToString("MMMM dd yyy") at
@rec1.Created.ToString("HH:mm tt") </span>
</div>
<div>@rec1.GetRecordField("Comment:").Values[0] </div>
<p class="commentfunctions">
<span class="glyphicon glyphicon-star small"></span> @endorseCount Endorsements
<span class="glyphicon glyphicon-star-empty small commentfunction"></span><a href="/governance/Endorse?recordid=@recordID3" title="Endorse"> Endorse</a>
<span class="glyphicon glyphicon-share-alt small commentfunction"></span><a href="?parentrecordid=@parentID&pId2=@recordID2&pId3=@recordID3&pId4=0&lvl=2#contour_form_Comment"> Reply</a>
<span class="glyphicon glyphicon-warning-sign small commentfunction"></span><a href="/governance/report-a-comment?parentrecordid=@recordID3"> Report abuse</a>
</p>
</li>
// Level 2
etc...
Robert
Thanks Robert, I get the idea, will have a play
Simon
is working on a reply...