• 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?

jdeg

Active member
#1
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} ?
 

Jeremy

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

Active member
#5
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?
 

Jeremy

Well-known member
#6
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.
 

jdeg

Active member
#7
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.
 

Jeremy

Well-known member
#8
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.
 

jdeg

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

Jeremy

Well-known member
#10
Template modifications are pre-render, so you add to the template. Any additional data or parameters should be added in the corresponding controllers.
 

jdeg

Active member
#12
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?