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

Forums / Developing with Sitefinity / Comments on news items

Comments on news items

18 posts, 0 answered
  1. Jackson
    Jackson avatar
    51 posts
    Registered:
    23 May 2008
    11 Jul 2008
    Link to this post
    I am trying to add the ability to comment on news items.  I see that this is possible because it commenting is actually part of Generic Content.  I am able to use the Content View Control and use the news provider to achieve this but I have no way to manage the comments.   I would love to be able to manage comments like they are in blogs. How would I go about adding comments to the news templates and is there any way for me to change the CMS management feature so that I'd be able to manage these.

    Thanks,
    Chris
  2. Szymon
    Szymon avatar
    22 posts
    Registered:
    04 Jan 2008
    13 Jul 2008
    Link to this post
    Hi,

    I'm also interested in this. I hope we can use comments on news the same way like on the blogs.
  3. Pepi
    Pepi avatar
    981 posts
    Registered:
    08 Dec 2016
    14 Jul 2008
    Link to this post
    Hello Szymon,

    To enable comments in the News module administration, you need to do the following:

    1. In the ~/Sitefinity/Admin/ControlTemplates/News/CommandPanel.ascx template, add a link button with ID "commentsLink":

    <asp:LinkButton runat="server" ID="commentsLink" Text="Comments"/> 

    2. Copy the ~/Sitefinity/Admin/ControlTemplates/Blogs/CommentsEdit.ascx, ~/Sitefinity/Admin/ControlTemplates/Blogs/CommentsList.ascx, and ~/Sitefinity/Admin/ControlTemplates/Blogs/CommentsView.ascx templates to the Sitefinity/Admin/ControlTemplates/News folder.
    You should also copy the resource files of these templates which are located in the App_LocalResources folder.

    Do let usknow if this helps.

    Kind regards,

    Pepi
    the Telerik team


    Instantly find answers to your questions at the new Telerik Support Center
  4. Jackson
    Jackson avatar
    51 posts
    Registered:
    23 May 2008
    14 Jul 2008
    Link to this post
    Awesome, that was an easy fix.  So what would be the best way for me to add comments on the public side? Is it for me to just use the content view control?
  5. Szymon
    Szymon avatar
    22 posts
    Registered:
    04 Jan 2008
    14 Jul 2008
    Link to this post
    Yes, this part worked nicely but I second Chris in question on how to add comments on the public site.

    I found this older thread that mentions overrideing the CommentsList control. But I'm confused a bit because in newer posts you often mention the generic ContentView control. Please advise us how to best implement this in the latest version.

    Thanks,
    -Szymon
  6. Pepi
    Pepi avatar
    981 posts
    Registered:
    08 Dec 2016
    15 Jul 2008
    Link to this post
    Hi Chris and Szymon,

    You can add CommentsList control in ~/Sitefinity/ControlTemplates/News/Modes/ListPageDetails.ascx template and use News View control instead of the Content View:

    <%@ Register Assembly="Telerik.Cms.Web.UI" Namespace="Telerik.Cms.Web.UI" TagPrefix="sfWeb" %> 
    <%@ Register Assembly="Telerik.Cms.Engine" Namespace="Telerik.Cms.Engine.WebControls" TagPrefix="sfWeb" %> 
    <%@ Register Assembly="Telerik.Cms.Web.UI" Namespace="Telerik.Web.UI.SpamProtection" TagPrefix="sfWeb" %> 
     
    <sfWeb:CssFileLink ID="CssFileLink1" FileName="~/Sitefinity/ControlTemplates/Libraries/librariesCommonLayout.css" Media="screen" runat="server" /> 
     
    ... 
     
    <div id="comments" class="sf_postComments"
        <sfWeb:CommentsList ID="commentsList" runat="server" CssClass="sf_commentsList"
            <Template> 
                <asp:Repeater ID="commentsRepeater" runat="Server"
                    <HeaderTemplate> 
                        <asp:PlaceHolder runat="server" ID="headerHolder"
                            <h2 class="sf_comments"
                                <asp:Literal ID="Literal1" runat="server" Text="Comments" /> 
                                &nbsp;<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> 
                           <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="date" id="commentDate" runat="server" > </abbr> 
                            </p> 
                            <asp:Label ID="text" runat="server"></asp:Label> 
                        </Template> 
                        
                        </sfWeb:CommentItem> 
                        
                        <sfWeb:CommentItem Id="authorCommentContainer" runat="server"  CssClass="sf_authorComment">  
                         <Template> 
                             <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="date" id="commentDate" runat="server"</abbr> 
                                 
                            </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"
                    <class="sf_commentMessage"
                        <asp:Literal ID="Literal2" runat="server" Text="Thank you for the comment! Your comment must be approved first"></asp:Literal> 
                    </p> 
                </asp:PlaceHolder> 
                <fieldset class="sf_postNewComment"
                    <legend>Post a comment!</legend> 
                    <ol> 
                        <li> 
                            <asp:Label ID="Label2" runat="Server" Text="Name:" AssociatedControlID="authorTxt"></asp:Label> 
                            <asp:TextBox ID="authorTxt" runat="server" ValidationGroup="commentInfo" size="30"></asp:TextBox> 
                            <asp:RequiredFieldValidator runat="server" ID="authorVal" ControlToValidate="authorTxt" 
                                    ErrorMessage="Name can't be empty!" Display="dynamic" ValidationGroup="commentInfo" 
                                    CssClass="sf_commentsValidator"></asp:RequiredFieldValidator> 
     
                        </li> 
                        <li> 
                            <asp:Label ID="Label3" runat="Server" Text="Email:" AssociatedControlID="emailTxt"></asp:Label> 
                            <asp:TextBox ID="emailTxt" runat="server" ValidationGroup="commentInfo" size="30"></asp:TextBox> 
                            <asp:RegularExpressionValidator runat="server" ID="emailVal" ControlToValidate="emailTxt" 
                                    ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ErrorMessage="Invalid email format!" 
                                    Display="dynamic" ValidationGroup="commentInfo" CssClass="sf_commentsValidator"></asp:RegularExpressionValidator> 
                        </li> 
                        <li> 
                            <asp:Label ID="Label4" runat="Server" Text="Your URL  (<em>optional</em>):" 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="Comment:" AssociatedControlID="commentTxt"></asp:Label> 
                            <asp:TextBox ID="commentTxt" runat="server" TextMode="MultiLine" ValidationGroup="commentInfo" Rows="8" Columns="40"></asp:TextBox> 
                             <asp:RequiredFieldValidator runat="server" ID="contentVal" ControlToValidate="commentTxt" 
                                    ErrorMessage="Comment can't be empty!" Display="dynamic" ValidationGroup="commentInfo" 
                                    CssClass="sf_commentsValidator"></asp:RequiredFieldValidator> 
                        </li> 
                        <li> 
                        <sfweb:spamprotector id="SpamProtector1" runat="server" cssclass="commentsValidator hide" 
                            validationgroup="commentInfo" 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="Post a comment" 
                            ValidationGroup="commentInfo" CssClass="sf_commentSubmit" /> 
                        </li> 
                    </ol> 
                </fieldset> 
            </Template> 
        </sfWeb:CommentsList> 
    </div> 

    For your convenience I have attached the modified version of the template.

    Do let us know if this helps.

    Sincerely yours,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  7. Szymon
    Szymon avatar
    22 posts
    Registered:
    04 Jan 2008
    16 Jul 2008
    Link to this post
    Hi,

    Thanks for providing this great example. It works like a charm :-)

    But I have another set of requirements:
    1. 1) Only the logged in users should be able to post comments - for anonymous users the "post a comment" section should be hidden.
    2. 2) The author field should be automatically set to the logged in user name.
    3. 3) The website should automatically redirect to the logged in user profile page (that is page on our website).
    4. 4) The news author should be able to edit and/or delete his comments.
    Hope you can give me at least some pointers where to start with all this.

    Regards,
    -Szymon
  8. Szymon
    Szymon avatar
    22 posts
    Registered:
    04 Jan 2008
    16 Jul 2008
    Link to this post
    And one more thing... How can I change the date format on a comment?

    -Szymon
  9. Pepi
    Pepi avatar
    981 posts
    Registered:
    08 Dec 2016
    17 Jul 2008
    Link to this post
    Hello Szymon,

    Please refer to the following online resources that will give you directions how to start your custom implementation:
        1. forum post
        2. KB article

    As to changing the format of the comment date, unfortunately it is not possible because the format is set in the code of CommentItem class and there is no way to override it. We will provide such opportunity in future versions of Sitefinity.

    Best wishes,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  10. nogatek
    nogatek avatar
    35 posts
    Registered:
    23 Apr 2008
    18 Jul 2008
    Link to this post
    Thanks for the great solution Pepe.

    I am implemented this successfully in the Modes/ListPageDetails.ascx page, but what I would like to do next is display the comment count (for each news item) in the Modes/ListPageMaster.ascx listing page.

    I have tried using some of the comments code, but so far no luck...

    Thanks, Mark

  11. Pepi
    Pepi avatar
    981 posts
    Registered:
    08 Dec 2016
    18 Jul 2008
    Link to this post
    Hello Mark,

    To achieve this you need to modify ~/Sitefinity/ControlTemplates/News/Modes/ListPageMaster.ascx template as follows:

    ... 
    <asp:Repeater ID="repeater" runat="server"
        <HeaderTemplate> 
            <ul class="sf_newsList"
        </HeaderTemplate> 
        <ItemTemplate> 
            <li> 
                ... 
                <class="sf_postComments"
                    <asp:HyperLink ID="CommentsLink" runat="server" NavigateUrl="{0}#comments"
                        <asp:Literal ID="Literal1" Text="Comments" runat="server"></asp:Literal> 
                        (<asp:Label ID="CommentsCount" runat="server"></asp:Label>
                    </asp:HyperLink> 
                </p> 
            </li> 
        </ItemTemplate> 
        <FooterTemplate> 
            </ul> 
        </FooterTemplate> 
    </asp:Repeater> 
    ... 

    i.e you should add the marked HTML in the ItemTemplate of the repeater listing all news items.

    Hope this helps.

    All the best,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  12. Szymon
    Szymon avatar
    22 posts
    Registered:
    04 Jan 2008
    18 Jul 2008
    Link to this post
    Hi,
    Is there a way to number the comments - i.e. display the list number next to each comment?

    I know we can use the <ol> elements and leave the <li> numbers but this is not very flexible. For example on Chnnel9 the numbers are displayed when you mouse over the comment header.

    Thanks,
    -Szymon
  13. nogatek
    nogatek avatar
    35 posts
    Registered:
    23 Apr 2008
    19 Jul 2008
    Link to this post
    Thanks Pepi! Works a treat. Cheers, Mark
  14. Pepi
    Pepi avatar
    981 posts
    Registered:
    08 Dec 2016
    21 Jul 2008
    Link to this post
    Hi Szymon,

    To achieve the required functionality, you can get the index of the item in the comments repeater in ~/Sitefinity/ControlTemplates/News/Modes/ListPageDetails.ascx template like this:

    ... 
    <sfWeb:CommentsListExtender ID="commentsList" runat="server" CssClass="sf_commentsList"
            <Template> 
                <asp:Repeater ID="commentsRepeater" runat="Server"
                    <HeaderTemplate> 
                         
                        <asp:PlaceHolder runat="server" ID="headerHolder"
                            <h2 class="sf_comments"
                                <asp:Literal ID="Literal1" runat="server" Text="Comments" /> 
                                &nbsp;<asp:Literal ID="commentsCount" runat="server"></asp:Literal> 
                            </h2> 
                        </asp:PlaceHolder> 
                        <ul class="sf_commentListing"
                    </HeaderTemplate> 
                    <ItemTemplate> 
                        <!-- comment goes here --> 
                        <%#Container.ItemIndex + 1%> 
                        <sfWeb:CommentItem Id="anonCommentContainer" runat="server" CssClass="sf_anonymousComment"> 
    ... 

    Please, explain in details if there is some misunderstanding.

    Sincerely yours,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  15. Eric Tangedahl
    Eric Tangedahl avatar
    12 posts
    Registered:
    11 Aug 2009
    28 Sep 2010
    Link to this post
    I need to remove the comments section from my Events module.  Is this done the same way?  When I go to "Sitefinity\Admin\ControlTemplates\Events" in don't see any .ascx files, just ContentVersionView.aspx.  Where should I be going?  I'm assuming I can just delete the content area for comments for events?

    Thanks,
    Eric
  16. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    28 Sep 2010
    Link to this post
    Hello Eric Tangedahl,

    Backend module

    Open web.config and file Events provider declaration in cmsEngine node.Then set allowComments="false" commentsModeration="false"

    Public control

    Drop the control - EventsView on a page and got to its Advanced Tab. Expand Comments properties section and from there you can disable public comments.

    All the best,
    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
  17. JAllen
    JAllen avatar
    34 posts
    Registered:
    23 Dec 2010
    07 Mar 2011
    Link to this post
    It may be a long shot, but I'm wondering if Szymon was ever were able to implement the restriction on viewing/adding a comment to logged in users?

    As his posts were a while ago, has this functionality been added since then?  We're running SF3.7 with SP4 - if anyone could show me how to do this, that'd be great.

    Thanks
  18. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    07 Mar 2011
    Link to this post
    Hello JAllen,

    We have not implemented comments restrictions per role or user in SP4. It could be done with a  custom template for ListPateDetails.ascx for news control. You can access the CommentsList control- from the code behind and hide it. You can store user IDs and roles in a separate database and decide whether to show or hide the comments based on the current principal.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Register for webinar
18 posts, 0 answered