+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / displaying blog post comments

displaying blog post comments

4 posts, 0 answered
  1. Biren
    Biren avatar
    23 posts
    Registered:
    02 Nov 2010
    20 Dec 2010
    Link to this post
    Hi,
    I have a page to display blog post details likes title, publish date, content. I have used sitefinity BlogPosts control for that. To display detail as per my requirement i have a user control derived from BlogPosts. The ascx code looks like this,

    <%@ Control Language="C#" %>
    <%@ Register Assembly="Telerik.Cms.Engine" Namespace="Telerik.Cms.Engine.WebControls"
        TagPrefix="sfWeb" %>
    <%@ Register Assembly="Telerik.Cms.Web.UI" Namespace="Telerik.Cms.Web.UI" TagPrefix="sfCtrl" %>
    <%@ Register Assembly="Telerik.Cms.Web.UI" Namespace="Telerik.Web.UI.SpamProtection"
        TagPrefix="sfWeb" %>
    <%@ Register Assembly="Telerik.Cms.Web.UI" Namespace="Telerik.Cms.Web.UI" TagPrefix="sfWeb" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Cms.Engine.WebControls" Assembly="Telerik.Cms.Engine" %>
    <sfWeb:CssFileLink ID="CssFileLink1" EmbeddedFileName="Telerik.Cms.Engine.Resources.ControlTemplates.Frontend.genericContentCommonLayout.css"
        FileName="" Media="screen" runat="server" />
    <telerik:JsFileLink ID="jsLink" runat="server" ScriptType="jQuery" />
    <div class="sf_singleContent">
        <div class="singleItemContent">
            <div>
                <div class="blogTitle">
                    <asp:Literal ID="Title" runat="server"></asp:Literal>
                </div>
                <asp:Panel ID="pnlContent" runat="server" CssClass="sf_genericContent">
                    <asp:Literal ID="content" runat="server"></asp:Literal>
                </asp:Panel>            
            </div>
        </div>
    </div>

    I want to display all comments for the post and text boxes[visitor name, comment] and a button to POST new comment on the page. How I can do that ?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    21 Dec 2010
    Link to this post
    Hi Biren,

    You have to add BlogCommentsList control to your template ( details mode)

    <div class="sf_postComments" runat="server" id="postCommentsPlh">
        <sfWeb:BlogCommentsList ID="commentsList" runat="server" CssClass="sf_commentsList" ValidationGroup="commentInfo">
                <LayoutTemplate>
            <asp:Repeater ID="commentsRepeater" runat="Server">
        <HeaderTemplate>
            <asp:PlaceHolder runat="server" ID="headerHolder">
                <h2 class="sf_comments">
                    <asp:Literal ID="Literal1" runat="server" Text="<%$Resources:Comments %>" />
                     <asp:Literal ID="commentsCount" runat="server"></asp:Literal>
                </h2>
            </asp:PlaceHolder>
            <ul class="sf_commentListing">
        </HeaderTemplate>
        <ItemTemplate>
            <!-- comment goes here -->
            <sfWeb:CommentItem Id="anonCommentContainer" runat="server" CssClass="sf_anonymousComment" >
             
             <Template>
               <p class="sf_commentAuthor">
                    <strong>
                        <asp:HyperLink ID="webSiteLink" runat="server" Visible="false" rel="nofollow"></asp:HyperLink>
                        <asp:Literal runat="Server" ID="authorName"  Visible="false"></asp:Literal>
                    </strong>
                    <%--<abbr class="sf_commentDate" id="commentDate" runat="server" > </abbr>--%>
                    <telerik:DateTimeLiteral ID="commentDateLiteral" runat="server" DateFormatString="" />
                </p>
                <asp:Label ID="text" runat="server"></asp:Label>
            </Template>
            
            </sfWeb:CommentItem>
            
            <sfWeb:CommentItem Id="authorCommentContainer" runat="server"  CssClass="sf_authorComment">
             <Template>
                 <p class="sf_commentAuthor">
                    <strong>
                        <asp:HyperLink ID="webSiteLink" runat="server" Visible="false" rel="nofollow"></asp:HyperLink>
                        <asp:Literal runat="Server" ID="authorName"  Visible="false" ></asp:Literal>
                    </strong>
                    <%--<abbr class="sf_commentDate" id="commentDate" runat="server"> </abbr>--%>
                    <telerik:DateTimeLiteral ID="commentDateLiteral" runat="server" DateFormatString="" />
                </p>
                <asp:Label ID="text" runat="server"></asp:Label>
             </Template>
             
           </sfWeb:CommentItem>
             
        </ItemTemplate>
        <FooterTemplate>
            </ul>
        </FooterTemplate>
    </asp:Repeater>
    <asp:PlaceHolder ID="moderationHolder" runat="server" Visible="false">
        <p class="sf_commentMessage">
            <asp:Literal ID="Literal2" runat="server" Text="<%$Resources:CommentMessageModeration %>"></asp:Literal>
        </p>
    </asp:PlaceHolder>
     
        <fieldset class="sf_postNewComment">
            <legend>Post a comment!</legend>
            <ol>
                <li>
                    <asp:Label ID="Label2" runat="Server" Text="<%$Resources:Name %>" AssociatedControlID="authorTxt"></asp:Label>
                    <asp:TextBox ID="authorTxt" runat="server" size="30"></asp:TextBox>
                    <asp:RequiredFieldValidator runat="server" ID="authorVal" ControlToValidate="authorTxt"
                            ErrorMessage="<%$Resources:NameEmpty %>" Display="dynamic"
                            CssClass="sf_commentsValidator"></asp:RequiredFieldValidator>
     
                </li>
                <li>
                    <asp:Label ID="Label3" runat="Server" Text="<%$Resources:Email %>" AssociatedControlID="emailTxt"></asp:Label>
                    <asp:TextBox ID="emailTxt" runat="server" size="30"></asp:TextBox>
                    <asp:RegularExpressionValidator runat="server" ID="emailVal" ControlToValidate="emailTxt"
                            ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ErrorMessage="<%$Resources:InvalidEmail %>"
                            Display="dynamic" CssClass="sf_commentsValidator"></asp:RegularExpressionValidator>
                </li>
                <li>
                    <asp:Label ID="Label4" runat="Server" Text="<%$Resources:WebSite %>" AssociatedControlID="webSiteTxt"></asp:Label>
                    <asp:TextBox ID="webSiteTxt" runat="server" size="30"></asp:TextBox>
                </li>
                <li class="texarea-wrapper">
                    <asp:Label ID="Label1" runat="Server" Text="<%$Resources:Comment %>" AssociatedControlID="commentTxt"></asp:Label>
                    <div>
                        <a href="#" class="formattingOptionsToggleBtn" onclick='if($(this).parent().hasClass("formattingOptions")){$(this).parent().removeClass("formattingOptions");$(this).text("Formatting options");}else{$(this).parent().addClass("formattingOptions");$(this).text("Hide formatting options"); } return false;'>Formatting options</a>
                         <telerik:RadEditor
                                runat="server"
                                ID="commentTxt"
                                ToolsFile="~/Sitefinity/ControlTemplates/Blogs/ToolsFile.xml"
                                EnableEmbeddedSkins="True"
                                Skin="Default"
                                Width="100%"
                                EditModes="Design">    
                         </telerik:RadEditor>  
                    </div
                     <asp:RequiredFieldValidator runat="server" ID="contentVal"
                            ControlToValidate="commentTxt"
                            ErrorMessage="<%$Resources:CommentEmpty %>"
                            Display="dynamic"
                            ValidationGroup="commentInfo"
                            CssClass="sf_commentsValidator">
                            <strong>Message text is required</strong>
                     </asp:RequiredFieldValidator>                                                                                                                   
                </li>          
                <li>
                <sfWeb:SpamProtector id="spamProtector" runat="server" cssclass="commentsValidator hide"
                    EnableCaptcha="true" Enabled="true" CaptchaFontWarp="High" CaptchaBackgroundNoise="High" CaptchaLineNoise="High"
                enableautobotdiscovery="true" enablehiddentextboxstrategy="true"
                    hiddentextboxerrormessage="Hidden TextBox has some text in it!" hiddentextboxlabel="Do not fill this textbox!"
                    hiddentextboxlabelcssclass="hide" hiddentextboxinputcssclass="hide" enablemintimeoutstrategy="true"
                    mintimeout="2" mintimeouterrormessage="Submission too fast!" />
                <asp:Button ID="submitBtn" runat="server" Text="<%$Resources:PostThisComment %>"
                    CssClass="sf_commentSubmit" />
                </li>
            </ol>
        </fieldset>
     
            </LayoutTemplate>
        </sfWeb:BlogCommentsList>
    </div>


    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Biren
    Biren avatar
    23 posts
    Registered:
    02 Nov 2010
    28 Dec 2010
    Link to this post
    Thanks Ivan. This is what i need :).

    I have one more quick question on the same. Instead of displaying date when the comment was posted i want to display timespan. I mean lets say i have a comment which was posted on 26th Dec. Instead of displaying date i want to display "2 days ago". Is it possible to do this in DateFormatString or is there a way to do this ?

    Thanks,
    Biren
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Dec 2010
    Link to this post
    Hi Biren,

    You need to calculate the value in a custom control that inherits from CommentsList or create a code behind of the template and there get the value of commentDateLiteral, then get the DateTime.Now value and return the ASP.NET System.TimeSpan.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
4 posts, 0 answered