1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Likes JS

Discussion in 'XenForo Development Discussions' started by silence, Nov 17, 2014.

  1. silence

    silence Well-Known Member

    So I'm coding up a custom usage of the likes, and it all works so far, however the function in xenforo.js 'XenForo.LikeLink' isn't executing to show the like_summary upon liking or unliking content.

    I'm not getting any errors it simply doesn't do the fancy scroll thing upon liking/unliking content.

    Are there any examples that describe how to do this, or what can I post to get help with this since I'm not exactly sure what the issue is D:

  2. Chris D

    Chris D XenForo Developer Staff Member

    Your controller action should return a view which takes care of loading the likes_summary template, etc.

    e.g. XenForo_ViewPublic_Post_LikeConfirmed
  3. silence

    silence Well-Known Member

    I copied the ProfilePost version as so:

    class PostComments_ViewPublic_Post_LikeConfirmed extends XenForo_ViewPublic_Base
        public function renderJson()
            $message = $this->_params['comment'];
            if (!empty($message['likeUsers']))
                $params = array(
                    'message' => $message,
                    'likesUrl' => XenForo_Link::buildPublicLink('post/comment-likes', $message, array('comment' => $message['comment_id']))
                $output = $this->_renderer->getDefaultOutputArray(get_class($this), $params, 'post_comment_likes_summary');
                $output = array('templateHtml' => '', 'js' => '', 'css' => '');
            $output += XenForo_ViewPublic_Helper_Like::getLikeViewParams($this->_params['liked']);
            return XenForo_ViewRenderer_Json::jsonEncodeForOutput($output);
    However it's still not working, the template 'post_comment_likes_summary' is the same as well.
  4. silence

    silence Well-Known Member

    I can see also when I use my like, it prints this to js console:
    While a profile post prints this:
    {"templateHtml":"\n\t\n\t<div class=\"likesSummary secondaryContent\">\n\t\t<span class=\"LikeText\">\n\t\t\tYou like this.\n\t\t<\/span>\n\t<\/div>\n","css":{"stylesheets":["likes_summary"],"urlTemplate":"css.php?css=__sentinel__&style=47&dir=LTR&d=1416215382"},"js":"","term":"Unlike","cssClasses":{"like":"-","unlike":"+"},"_visitor_conversationsUnread":"8","_visitor_alertsUnread":"1"}
    So I'm unsure what I'm missing D:
  5. silence

    silence Well-Known Member

    Ok switching to the template 'likes_summary' fixes the console output but the animation still isn't happening.
  6. silence

    silence Well-Known Member

    Ugh every time I post i find a solution quickly...
    Had something to do with:
    data-container="#likes -ps-{$comment.comment_id}"
    and changing it to:
    fixes the issue.

    No idea why though D:
  7. Chris D

    Chris D XenForo Developer Staff Member

    data-container should reference the container where the likes should appear
    silence likes this.

Share This Page