Copied to clipboard

Flag this post as spam?

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


  • khansaa111 25 posts 55 karma points
    Jul 10, 2015 @ 11:22
    khansaa111
    0

    comment in umbraco

    I need to add the comment function under my Articles or posts in umbraco , so i do everything to get the result , " the creation of document type called Comment with a textstring property called commentName and a textbox multiple property called commentMessage " also I authorized the Comment document type as child document type to mu textpage document type .

    and the creation of this script in the scripting file , after that i added it below the bodyText in my template.

    but

    but an error message appears "Error loading MacroEngine script (file: Comment.cshtml) "

    I dont knew why ?

    this is the script

    @using umbraco.cms.businesslogic.web

    @* Some global variables *@

    @{ var successfulPost = false; var name = Request["name"]; var message = Request["message"]; }

    @* Handle form post: create a new document if a valid post*@

    @if (IsPost) { if (name!="" && message !="") { var dt = DocumentType.GetByAlias("Comment");

    @* Make sure its a valid document type alias *@
    
    if (dt != null)
    {
    
      var author = umbraco.BusinessLogic.User.GetUser(0);
    
      var doc = Document.MakeNew("Comment", dt, author, Model.Id);
      doc.getProperty("commentName").Value = name;
      doc.getProperty("commentMessage").Value = message;
    
      @* Tell umbraco to publish the document *@
    
      doc.Publish(author);
      umbraco.library.UpdateDocumentCache(doc.Id);
    
      successfulPost = true;
    }
    

    } }

    @* Render the Html *@


    @if (successfulPost) {

    Successful post

    Thank you @name for your message:

    @message

    }

    Comments:

    @foreach (dynamic c in Model.Comment) {

    @c.commentMessage

    By : @c.commentName (at @c.CreateDate)

    }

    Add a new comment:



  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jul 10, 2015 @ 12:00
    Ismail Mayat
    0

    In umbracoSettings.config change line

    <MacroErrors>inline</MacroErrors>
    

    to

    <MacroErrors>throw</MacroErrors>
    

    That will give you error screen with more detailed information should to debug. Also as you are using v7 how come you are not using ContentService to create the comment, Document.MakeNew is being deprecated see https://our.umbraco.org/documentation/Reference/Management-v6/Services/ContentService

    Regards

    Ismail

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 10, 2015 @ 12:20
    Dennis Aaen
    0

    Hi khansaa111,

    Perhaps you should have a look on this package. https://our.umbraco.org/projects/website-utilities/ucommentsy

    Maybe it has the features that you are looking for.

    Hope this helps,

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft