Conditionals & thread title in callback for a template hook?

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} ?
 
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.
 
great, thanks for responding. Do you happen to know what the thread title variable is?
 
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?
 
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.
 
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.
 
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.
 
Oh okay. Now I'm confused though. I was under the impression that template modifications were only for templates, not running code.
 
Template modifications are pre-render, so you add to the template. Any additional data or parameters should be added in the corresponding controllers.
 
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?
 
Back
Top Bottom