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

Likes JS

silence

Well-known member
#1
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:

Thanks!
 

Chris D

XenForo developer
Staff member
#2
Your controller action should return a view which takes care of loading the likes_summary template, etc.

e.g. XenForo_ViewPublic_Post_LikeConfirmed
 

silence

Well-known member
#3
Your controller action should return a view which takes care of loading the likes_summary template, etc.

e.g. XenForo_ViewPublic_Post_LikeConfirmed
I copied the ProfilePost version as so:

Code:
<?php

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');
        }
        else
        {
            $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.
 

silence

Well-known member
#4
I can see also when I use my like, it prints this to js console:
Code:
{"templateHtml":"","css":"","js":"","term":"Unlike","cssClasses":{"like":"-","unlike":"+"},"_visitor_conversationsUnread":"8","_visitor_alertsUnread":"0"}
While a profile post prints this:
Code:
{"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:
 

silence

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

No idea why though D: