Developer forum

Forum » CMS - Standard features » Information / Notification about new comments?

Information / Notification about new comments?

Jens Jakob Vedel Kristensen
Jens Jakob Vedel Kristensen
Reply

Hi, 

 

Regarding the standard feature of commenting on pages:

 

1) Where can the editor find information about new comments and manage the comments? Where do you go in DW backend for an overview of new comments, so you don't have to go through each single page to check if there are new comments?

 

2) Is it possible to have nested comments? Like answers or remarks to an existing comment?

 

 


Replies

 
Lars Larsen
Lars Larsen
Reply

Hi Jens

There is unfortunately no place in the backend where you can see an overview of new comments. For that purpose I have earlier used the the API and subscribed to "Commenting.OnAfterComment" and from there send an email to the website editor.

As far as I know it is not possible to nest comments.

 
Nicolai Pedersen
Reply
This post has been marked as an answer

HI Jens Jakob

As Lars says, there is not a place where you can see all comments.

But the system can send notifications to the site owner with information with new comments, and that notification can contain links to delete, approve or see the new comment.

The system does not support nested comments and answers - you could use the forum for that.

It supports like/nolike on comments though

 

Attached find a set of templates with all the features (Razor and HTML editions).

Votes for this answer: 1
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

What about using something like DataLists and set up a protected page in the frontend to manage the comments?

 

Imar

 
Jens Jakob Vedel Kristensen
Jens Jakob Vedel Kristensen
Reply

Hi Lars

 

Thanks, although I was hoping that a comment notification was a standard feature, and not something you would have to custom build.

 

Was it a troublesome process for you to make it work?

 
Jens Jakob Vedel Kristensen
Jens Jakob Vedel Kristensen
Reply

Hi Nicolai

 

Thank you for the fast reply, and the razor templates.

 

When you say that it is possible to send comment notifications to a given e-mail address, will it require some custom code, like Lars mentions? Or have I just missed a setting for this somewhere in the Management Center abyss? :-)

 

I would like to propose a comment management context as a feature request to be made as a part of the DW backend. When site owners create websites in order to create dialogue and interaction with their customers, then it is necessary for them to have a meaningful, easy way of managing the comments/reviews. Otherwise it becomes a real pain, and other platforms might be the preferred choice. Managing the comments should be as easy as managing your content, especially when dialogue and reviews are a central part of your marketing strategy.

 

The solution could be a rather simple list of all the comments, with sorting/filtering according to the comment data/fields you already have. Buttons for each comment to edit, approve, or delete the comment. And on the new dashboard in DW9 there could be a section, that would show new comments with link to the comment list. That would be awesome.

 

 
Jens Jakob Vedel Kristensen
Jens Jakob Vedel Kristensen
Reply

Hi Imar

 

Thank you for the suggestion. I tried that, but somehow I couldn't get output from the datalist, when I set it up for comment data?

 

I made a really simple datalist with only one condition, e.g. CommentRating <= 4, or CommentActive = true. But I couldn't retrieve any comment data?

 

Does anyone have a suggestion for tweaking the datalist settings?

 

condition-active.JPG condition-rating.JPG
 
Lars Larsen
Lars Larsen
Reply

Hi Jens

I don't think it was a big job. I created a website settings itemtype to hold settings like FromEmail, ToEmail, Subject and FromEmailName used when sending the email notification. The code is here:

namespace Notifications
{
    using System.Linq;
    using System.Net.Mail;
    using System.Text;
    using System.Web;

    using Dynamicweb;
    using Dynamicweb.Content.Commenting;
    using Dynamicweb.Content.Items;
    using Dynamicweb.Notifications;
    using Dynamicweb.Rendering;

    [Dynamicweb.Extensibility.Subscribe(Commenting.OnAfterComment)]
    public class CommentingOnAfterComment : Dynamicweb.Extensibility.NotificationSubscriber
    {
        public override void OnNotify(string notification, Dynamicweb.Extensibility.NotificationArgs args)
        {
            if (HttpContext.Current.Request.UrlReferrer == null)
            {
                return;
            }

            var ws = ItemManager.Storage.Open("WebsiteSettings").SelectAll().FirstOrDefault();

            if (ws == null)
            {
                return;
            }

            var commentArgs = args as Commenting.CommentArgs;
            var fromEmail = ws.ContainsKey("FromEmail") ? ws["FromEmail"].ToString() : "";
            var toEmail = ws.ContainsKey("ToEmail") ? ws["ToEmail"].ToString() : "";
            var subject = ws.ContainsKey("Subject") ? ws["Subject"].ToString() : "";
            var fromEmailName = ws.ContainsKey("FromEmailName") ? ws["FromEmailName"].ToString() : "";
            var template = new Template(Input.Request("Comment.NotifyTemplate"));

            if (commentArgs != null)
            {
                Renderer.RenderComment(template, commentArgs.Comment);
            }

            template.SetTag("Comment.Referrer", HttpContext.Current.Request.UrlReferrer.AbsoluteUri);
            
            EmailHandler.Send(new MailMessage
                              {
                                  Subject = subject,
                                  From = new MailAddress(fromEmail, fromEmailName),
                                  Sender = new MailAddress(fromEmail, fromEmailName),
                                  To = 
                                  {
                                      toEmail
                                  },
                                  IsBodyHtml = true,
                                  Body = template.Output(),
                                  BodyEncoding = Encoding.UTF8,
                                  SubjectEncoding = Encoding.UTF8,
                                  HeadersEncoding = Encoding.UTF8
                              });
        }
    }
}

 
Jens Jakob Vedel Kristensen
Jens Jakob Vedel Kristensen
Reply

Thank you Lars :-) That is a big help.

 

Good idea with the website settings for containing the e-mail variables. Did you also make a website setting for selecting email template?

 
Lars Larsen
Lars Larsen
Reply

Hi Jens

The template for the notification email is stored in a hidden field (Comment.NotifyTemplate) in the comment template. In this way you can have different email notification templates for different comment types.

 
Nicolai Pedersen
Reply

Dynamicweb already has support for sending these emails. If you look at the templates I've attached earlier, you can see 2 sections of information that will notify the website owner and users that has made comments on the page/product. It looks like this:

 

<input type="hidden" name="Comment.Notify" value="true" />
		<input type="hidden" name="Comment.NotifyTemplate" value="Comments/Notify.html" />
		<input type="hidden" name="Comment.NotifySubject" id="Comment.NotifySubject" value="New Comment: " />
		<input type="hidden" name="Comment.NotifySenderEmail" value="noreply@dynamicweb.dk" />
		<input type="hidden" name="Comment.NotifySenderName" value="Website comment engine" />
		<input type="hidden" name="Comment.NotifyEmail" value="to@me.com" />
		
		<input type="hidden" name="Comment.Reply.Notify" value="true" />
		<input type="hidden" name="Comment.Reply.NotifyTemplate" value="Comments/ReplyNotify.html" />
		<input type="hidden" name="Comment.Reply.NotifySubject" value="Someone made a reply on your comment..." />
		<input type="hidden" name="Comment.Reply.NotifySenderEmail" value="noreply@dynamicweb.dk" />
		<input type="hidden" name="Comment.Reply.NotifySenderName" value="Name Of My Website" />

BR Nicolai

 
Jens Jakob Vedel Kristensen
Jens Jakob Vedel Kristensen
Reply

Hi Nicolai

Thank you for the templates. I have tried the razor version, and the notifications are sent on submit.

However, the actual comment is not saved on the particular page? 

DW Support also tried both templates and only the html version worked as intended.

Do you have a suggestion as to why the razor version does not save the comment you submit?

Is there some values or IDs we need to modify in the template to match the specific solution?

Thank you in advance

 
Nicolai Pedersen
Reply
This post has been marked as an answer

The attached razor version is made for products, so the form in Comment.cshtml has 2 sections - one for ecommerce and one for products. You should make sure you use the page version

Votes for this answer: 1
 
Jens Jakob Vedel Kristensen
Jens Jakob Vedel Kristensen
Reply

Hi Nicolai

Thanks - I did not notice that the page version was deactivated. It works. #hooray

The only thing I can't seem to get right in the razor notify-template is the link to the page. It should render the link to the page right below the "New comment from", but in my case nothing renders.

It uses this tag: @GetGlobalValue("Comment.Referrer").

The same tag works fine in the html version. 

Have you experienced this? 

 
Nicolai Pedersen
Reply

In the template I attached, the referer link comes from these tags:

@{
    var hrefAttributeGoToComment = string.Format("{0}#comment{1}", GetString("Comment.Referrer"), GetString("ID"));
    var hrefAttributeDeleteComment = string.Format("{0}?Comment.ID={1}&Comment.Command=delete&Comment.Token={2}", GetString("Comment.Referrer"), GetString("ID"), GetString("Token"));
    var hrefAttributeDeactivateComment = string.Format("{0}?Comment.ID={1}&Comment.Command=activate&Comment.Active=False&Comment.Token={2}", GetString("Comment.Referrer"), GetString("ID"), GetString("Token"));
    var hrefAttributeActivateComment = string.Format("{0}?Comment.ID={1}&Comment.Command=activate&Comment.Active=True&Comment.Token={2}", GetString("Comment.Referrer"), GetString("ID"), GetString("Token"));
}

GetGlobalValue will not work in a mail template since it works in the context of a pageview which is not there when sending mails.

 

You must be logged in to post in the forum