Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Profiterole 232 posts 264 karma points
    Apr 27, 2011 @ 15:02
    Profiterole
    0

    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

    Apr 28, 2011 @ 10:53

    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

  • Profiterole 232 posts 264 karma points
    May 06, 2011 @ 17:26
    Profiterole
    0

    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?

  • Profiterole 232 posts 264 karma points
    May 06, 2011 @ 18:23
    Profiterole
    0

    Ok, after some searches : set defaultvalue to [@recordid] and it saves the questry string

  • Jay 12 posts 32 karma points
    Apr 10, 2012 @ 08:00
    Jay
    0

    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.

  • Profiterole 232 posts 264 karma points
    Apr 10, 2012 @ 17:08
    Profiterole
    0

    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 :

    <xsl:for-each select="$records[string(./fields/parentid//value) = '']">     
              <xsl:call-template name="showcomments">
                <xsl:with-param name="comment" select="."/>
              </xsl:call-template>
    </xsl:for-each>

    and then :


    display the "main" comment and look for answers

         <xsl:variable name="parentID" select="id"/>
         <xsl:for-each select="$records[string(./fields/parentid//value) = $parentID]">
             <xsl:sort select="created" order="ascending"/>

    display them

         </xsl:for-each>

           
    <p style="text-align:right; margin-right:5px;">
                       <a href="?recordid={id}&amp;#form">Answer</a>
            </p>

    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!

  • Jay 12 posts 32 karma points
    Apr 11, 2012 @ 08:43
    Jay
    0

    hi Profiterole,

    i've tried your code bt it still gives me error on:

    <xsl:call-templatename="showcomments">

    if possible then please give me brief description to start with scratch.

     

    Thanks.

  • Profiterole 232 posts 264 karma points
    Apr 11, 2012 @ 15:01
    Profiterole
    0

    Hi, the showcomments template is the second part of my code. Here's my whole xslt (with french variables). Take a look at this :

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:umbraco.contour="urn:umbraco.contour"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets umbraco.contour ">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>
        <xsl:variable name="records" select="umbraco.contour:GetRecordsFromForm('a4c73fec-610a-4970-9d1b-89015d00ac07')/uformrecord[state = 'Approved']"/>

    <!-- XSLT  -->
    <xsl:template match="/">

    <xsl:variable name="numberOfComments" select="7"/>

      <xsl:variable name="pageNumber">
        <xsl:choose>
          <xsl:when test="umbraco.library:RequestQueryString('page') &lt;= 0 or string(umbraco.library:RequestQueryString('page')) = '' or string(umbraco.library:RequestQueryString('page')) = 'NaN'">1</xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="umbraco.library:RequestQueryString('page')"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>

       <xsl:variable name="numberOfRecords">
            <xsl:value-of select="count($records[./fields/autoriserlapublication//value = 'Oui' and string(./fields/parentid//value) = ''])"/>
      </xsl:variable>
      


      <xsl:if test="$numberOfRecords &gt; $numberOfComments">

            <xsl:if test="(($pageNumber ) * $numberOfComments) &lt; ($numberOfRecords)">
                      <div style="float:left;">
              <span class="meta-nav">&#171; </span>
              <a href="?page={$pageNumber +1}">anciens commentaires</a>
                                </div>
            </xsl:if>

      </xsl:if>



            <xsl:if test="$pageNumber &gt; 1">
                  <div style="float:right;">
              <a href="?page={$pageNumber -1}">commentaires récents</a>
              <span class="meta-nav"> &#187;</span>
                            </div>
            </xsl:if>

      <br/>
        <br/>

      
       <xsl:for-each select="$records[./fields/autoriserlapublication//value = 'Oui' and string(./fields/parentid//value) = '']">
            <xsl:if test="position() &gt; $numberOfComments * (number($pageNumber)-1) and
          position() &lt;= number($numberOfComments * (number($pageNumber)-1) +
          $numberOfComments )">
              <xsl:call-template name="showcomments">
                <xsl:with-param name="comment" select="."/>
              </xsl:call-template>
            </xsl:if>
          </xsl:for-each>
      
       <xsl:if test="$numberOfRecords &gt; $numberOfComments">

            <xsl:if test="(($pageNumber ) * $numberOfComments) &lt; ($numberOfRecords)">
                      <div style="float:left;">
              <span class="meta-nav">&#171; </span>
              <a href="?page={$pageNumber +1}">anciens commentaires</a>
                                </div>
            </xsl:if>

      </xsl:if>

            <xsl:if test="$pageNumber &gt; 1">
                  <div style="float:right;">
              <a href="?page={$pageNumber -1}">commentaires récents</a>
              <span class="meta-nav"> &#187;</span>
                            </div>
            </xsl:if>
    </xsl:template>

    <!-- mon code -->

            
      <xsl:template name="showcomments">
        <xsl:param name="comment"/>
          
    <xsl:variable name="divColor">
    <xsl:choose>
    <xsl:when test="position() mod 2 = 0">
    #B9D741
    </xsl:when>
    <xsl:otherwise>
    #64C7FE
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>
                      <div style="background:{$divColor}; padding: 2px 8px 2px 5px; border-radius:15px;">

       <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,'&#xD;&#xA;','\r\n')" disable-output-escaping="yes" /></cite>
        </p>

         <xsl:variable name="parentID" select="id"/>
         <xsl:for-each select="$records[string(./fields/parentid//value) = $parentID]">
             <xsl:sort select="created" order="ascending"/>

           
                  <xsl:if test="./fields/autoriserlapublication//value = 'Oui'">

           <p style="padding:2px 2px 2px 2px; margin-left:30px; background:#F7F7F7;">
            Le <xsl:value-of select="umbraco.library:LongDate(created)"/>, <b><xsl:value-of select="./fields/nom//value"/></b> a répondu : <br/>
            <cite> <xsl:value-of select="umbraco.library:Replace(./fields/message//value,'&#xD;&#xA;','\r\n')" disable-output-escaping="yes" /></cite>
           </p>
           </xsl:if>
           
                        </xsl:for-each>
               <p style="text-align:right; margin-right:5px;">
                       <a href="?recordid={id}&amp;#form" style="color:#000;">Répondre</a>
            </p>
                   

             </div>
    <br/>
    </xsl:template>

    </xsl:stylesheet>
  • Jay 12 posts 32 karma points
    Apr 11, 2012 @ 15:20
    Jay
    0

    Thank you Profiterole,

    i'll try it.

    again thanx.

  • Robert Brown 18 posts 38 karma points
    May 28, 2014 @ 15:29
    Robert Brown
    0

    Reviving an old thread.  

    I need to do this in version 7. Has anyone done this using Razor syntax?

     

    Robert

  • Simon steed 376 posts 688 karma points
    Sep 03, 2014 @ 19:40
    Simon steed
    0

    Ditto - how did you get on Robert?

  • Robert Brown 18 posts 38 karma points
    Sep 04, 2014 @ 17:22
    Robert Brown
    0

    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>&nbsp;@endorseCount Endorsements

    <span class="glyphicon glyphicon-star-empty small commentfunction"></span><a href="/governance/Endorse?recordid=@recordID" class="vote-up" title="Endorse">&nbsp;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">&nbsp;Reply</a>

                    <span class="glyphicon glyphicon-warning-sign small commentfunction"></span><a href="/governance/report-a-comment?parentrecordid=@recordID">&nbsp;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>&nbsp;@endorseCount Endorsements

    <span class="glyphicon glyphicon-star-empty small commentfunction"></span><a href="/governance/Endorse?recordid=@recordID3" title="Endorse">&nbsp;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">&nbsp;Reply</a>

                    <span class="glyphicon glyphicon-warning-sign small commentfunction"></span><a href="/governance/report-a-comment?parentrecordid=@recordID3">&nbsp;Report abuse</a>

                </p>

            </li>

    // Level 2

    etc...

    Robert

  • Simon steed 376 posts 688 karma points
    Sep 05, 2014 @ 12:22
    Simon steed
    0

    Thanks Robert, I get the idea, will have a play

    Simon

Please Sign in or register to post replies

Write your reply to:

Draft