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

Conditionals & thread title in callback for a template hook?

Discussion in 'XenForo Development Discussions' started by jdeg, Aug 4, 2013.

  1. jdeg

    jdeg Active Member

    I'm very new to creating addons for XF. I more than likely don't make any sense yet :)

    I'm using the hook "message_below" and want to say "If first post on the page, do this"

    I understand I can use {$post.position} % {$xenOptions.messagesPerPage} == 0 to do this directly in the template, but will the callback have the same access to the params or do they have to be explicitly passed? I see params="{xen:array 'post={$message}','message_id={$messageId}'}" in the hook so I assume things are being passed, right?

    I also need to get the thread title. What do I use to get that? {$post.title} ?
     
  2. Jeremy

    Jeremy XenForo Moderator Staff Member

    Template hooks (which are deprecated in 1.2, in favor of the more powerful Template Modifications) inject unprocessed code into templates. So yes, anything that is available in the template will be available to your template hook. The same thing applies to template hooks.
     
    jdeg likes this.
  3. jdeg

    jdeg Active Member

    great, thanks for responding. Do you happen to know what the thread title variable is?
     
  4. Jeremy

    Jeremy XenForo Moderator Staff Member

    Not off the top of my head, no. Probably $thread.title.
     
  5. jdeg

    jdeg Active Member

    According to this it looks like it should be $thread.title, but I can't get it to output anything other than "title". In my Listener.php file I'm simply doing a $contents .= $thread.title; to test. Is something not right there?
     
  6. Jeremy

    Jeremy XenForo Moderator Staff Member

    Does your add-on need to work in 1.1?

    If you look at the thread_view template and search for <xen:title> you'll find the correct variable.
     
  7. jdeg

    jdeg Active Member

    Doesn't need to work in 1.1, no.

    I meant that literally the word title is output when I use $thread.title in my Listener.php file.
     
  8. Jeremy

    Jeremy XenForo Moderator Staff Member

    If you don't need it to work in 1.1, you shouldn't be using listeners or template hooks. They've been deprecated in favor of template modifications. You should be using that. In your template modification, add:

    Code:
    {xen:raw $thread.title}
    And see what happens.
     
  9. jdeg

    jdeg Active Member

    Oh okay. Now I'm confused though. I was under the impression that template modifications were only for templates, not running code.
     
  10. Jeremy

    Jeremy XenForo Moderator Staff Member

    Template modifications are pre-render, so you add to the template. Any additional data or parameters should be added in the corresponding controllers.
     
  11. jdeg

    jdeg Active Member

    Okay, I'll have to do some more reading. Thanks for your help!
     
  12. jdeg

    jdeg Active Member

    I'm still trying to wrap my head around this, unfortunately. Some questions....

    How do I get data to my Listener.php file for processing, for example, $thread.title

    What listener event should I be using to pass data back to be used in a template modifiation?
     
  13. Jeremy

    Jeremy XenForo Moderator Staff Member

Share This Page