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

Adding Like Ratio in Messages

Discussion in 'XenForo Development Discussions' started by Geocodes, Jul 31, 2013.

  1. Geocodes

    Geocodes Member


    This is my first time developing for Xenforo so bear with me if I say something stupid haha. I wanted to create an add-on to show the ratio between likes received and likes given for each user's post.

    This is how I'm approaching it:

    Created a template_hook for "extra_user_info" to run 'Like_Ratio_Listener' class and function 'template_hook'

    My code in Like_Ratio_Listener (I already created a model to run an sql query to grab the liked given and liked received then dividing them to get the ratio. Right now, I need to find a way to grab the userid from the message for $USERIDHERE to output the ratio :

        public static function template_hook($hookName, &$contents, array $hookParamsXenForo_Template_Abstract $template){
    $hookName == 'message_user_info_extra')
    $model = new LikeRatio_Model_LikeRatioModel();
    $input = array('ratio'=> $model -> getAllLikesGiven($USERIDHERE));
    $ourTemplate $template->create('like_ratio_post'$input);
    $rendered $ourTemplate->render();
    $contents .= $rendered;
    3. So my main question is, how would I grab the user_id of the message to put it into my model.

    Thank you so much for the help!
  2. Jeremy

    Jeremy XenForo Moderator Staff Member

    Template Hooks inject code that is later rendered. You cannot get the current post user id when you are using template hooks.

Share This Page