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

fetch_threadinfo equivalent?

Discussion in 'XenForo Development Discussions' started by Jafo, Oct 21, 2014.

  1. Jafo

    Jafo Active Member

    If I have the ID of a thread, how would I go about fetching the info on it? Is this cached?
  2. Chris D

    Chris D XenForo Developer Staff Member

    No, it is not cached.

    There's not a whole lot of information here to know what you need or where you'll be using the code, but one way of accessing the thread info is:

    $threadModel XenForo_Model::create('XenForo_Model_Thread');

    $thread $threadModel->getThreadById($threadId);
  3. Jafo

    Jafo Active Member

    Thanks Chris. Well maybe I am going about this the wrong way then. I have a listener listening on the template_hook event. I am trying to get the threads reply_count value but I don't think this info is available in any of the arguments passed to the event, but maybe I am wrong? I obviously don't want to query thread info for each time a post in a thread is parsed.
  4. Chris D

    Chris D XenForo Developer Staff Member

    I really need to know exactly what you want to achieve.

    It may be that you have to query it if the reply_count value isn't available in that template hook. Without knowing what template hook, it's going to be difficult.

    Also, template hooks are officially deprecated so you should be using the built in Template Modification system for templates; though, again, if the parameter isn't available to the template then maybe the template hook is more appropriate.

    Unfortunately I can only speculate at this point.
  5. Jafo

    Jafo Active Member

    Chris, thanks, this is the first I have used the Template Modification System so bear with me. :)

    I would like to hook into the message template where currently the message_content hook is located. Right after the tag: </article>

    I would like it if I had the the thread info there, without having to query it each time. From what I have read of the documentation, the only thing passed to a callback template modification is the match. I need to know the current post position and the total reply_count if the thread in the callback method..
  6. Brogan

    Brogan XenForo Moderator Staff Member

    If you dump $thread in the message template, you should find that reply_count is available.

    {xen:helper dump, $thread}
  7. Jafo

    Jafo Active Member

    Okay, but I don't want to edit the template directly?
  8. Brogan

    Brogan XenForo Moderator Staff Member

    I was pointing out that the reply_count is available in the template already.

    As Chris has already said, use a TM to perform any edits as required.
  9. Jafo

    Jafo Active Member

    Sorry Brogan, still wrapping my head around the TMS.. I see what you are saying now. I just have to change the paradigm of my code to this new system. Thanks!
  10. Jafo

    Jafo Active Member

    How would you dump the info about the post being rendered in the message template?
  11. Jafo

    Jafo Active Member

    I have tried:

    {xen:helper dump, $post}

    {xen:helper dump, $message}

    To no avail..

Share This Page