Copied to clipboard

Flag this post as spam?

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


  • Eran Meir 401 posts 543 karma points
    Apr 11, 2011 @ 18:27
    Eran Meir
    0

    UComment and Razor

    has anyone tried working with UComment and razor and want to share some code like number of comments of node and getting comments for a node?

  • saintwright 69 posts 78 karma points
    Jun 29, 2011 @ 01:27
    saintwright
    0

    I just created a class library project with a static class (see below).  Then in one of my Templates I used the razor code:

    @UcommentHelper.Comments.GetCommentCountForNode(@item.Id) Comment(s)

    //static class UcommentHelper

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using umbraco.DataLayer;
    using umbraco.businesslogic;
    using umbraco.MacroEngines;

    namespace UcommentHelper
    {
        public static class Comments
        {
            public static string GetCommentCountForNode(int nodeid)
            {
                ISqlHelper helper = DataLayerHelper.CreateSqlHelper(umbraco.GlobalSettings.DbDSN);
       
                int? id = (int?)helper.ExecuteScalar<Int32>("select count(*) from comment where nodeid = @nodeid and spam != 1", new IParameter[] { helper.CreateParameter("@nodeid", nodeid) });
                    if(id.HasValue)
                    {
                      return id.ToString();
                    }
                    return "";
            }
             
        }
    }

  • Kouzzmitch 13 posts 36 karma points
    Oct 29, 2011 @ 19:58
    Kouzzmitch
    0

    I've translated ucommentlisctcomment to razor

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using umbraco.MacroEngines
    @using UComment
    @using System.Xml.XPath

    @{
       
        var title = Model.Name;
        XPathNodeIterator nodesroot = XSLTLibrary.GetCommentsForNode(Model.Id);
        XPathNodeIterator nodes = nodesroot.Current.Select("//comment");
        int cnt = nodes.Count;
           
    }
    @functions {
    }
        @if (cnt > 0)
        {
            nodes.MoveNext();
            <h3>Comments for "@title": @cnt.</h3>
            <ol class="commentlist">
            @for (int i = 0; i < cnt; i++)
            {
               
                XPathNavigator cur = nodes.Current;
                string url = cur.SelectSingleNode("./website").Value;
                string name = cur.SelectSingleNode("./name").Value;
                string email = cur.SelectSingleNode("./email").Value;
         
                <li class="comment alt" id="[email protected]("id","")">
                    <div class="comment-author vcard">
                        <img class="photo avatar avatar-32 photo" width="32" height="32" src="@UComment.XSLTLibrary.getGravatar(email, 40, "")" alt="Gravatar of @name"/>
                        <span class="fn n">
                        @if (!String.IsNullOrWhiteSpace(url))
                        {@name}
                        else
                        {
                            <a class="url url" rel="external nofollow" href="@url">@name</a>
                        }
                        </span>
                    </div>
                    <em class="comment-meta">
                        Published @umbraco.library.LongDate(cur.GetAttribute("created", ""), true, " at ")
                    </em>
                    <p>
                        @Html.Raw(umbraco.library.ReplaceLineBreaks(cur.SelectSingleNode("./message").InnerXml))
                    </p>
                </li>
               
                nodes.MoveNext();
                i++;
            }
            </ol>
        }
       
       
    and dont forget to change &amp; to &

    ucomment.library.base

            public static string GetGravatarImage(string email, int size)
            {
                if (isValidEmail(email))
                {
                    return string.Format("http://www.gravatar.com/avatar/{0}?s={1}&d=wavatar", umbraco.library.md5(email), size.ToString());
                }
                else
                {
                    return "";
                }
            }

  • Eran Meir 401 posts 543 karma points
    Oct 29, 2011 @ 20:11
    Eran Meir
    0

    thank you both for your help

  • Niek 5 posts 25 karma points
    Jan 30, 2012 @ 13:13
    Niek
    0

    I'm also trying to use Razor with the uComment package but I'm getting the following error when saving the Razor file:

    The type or namespace name 'XSLTLibrary' does not exist in the namespace 'UComment' (are you missing an assembly reference?)

    The error is referencing the following line:

    XPathNodeIterator nodesroot = UComment.XSLTLibrary.GetCommentsForNode(Model.Id);

    The UComment.dll is in the Umbraco /bin directory and I've checked the UComment source but the XSLTLibrary should be there.

    Am I missing something?

  • Blake Clerke 104 posts 347 karma points
    Jan 13, 2013 @ 18:50
    Blake Clerke
    0

    Did you ever figure out the XSLTLibrary does not exist error you were getting? I get the same error which is why I'm asking. I'm just using a seperate razor file for my news feed and wanted to pull the number of comments associated with a post but I'm not sure how.

  • Mark 4 posts 24 karma points
    May 22, 2013 @ 15:39
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies