XF 2.2 How can I add thread title as parameter in a callback

rhodes

Active member
Hello,

I use some widgets in a thread view sidebar. One of the widgets uses the current thread title as a parameter. I've tried this

<xf:callback class="MyAddon\\MyClass" method="mymethod" params="['{$thread.title}']" ></xf:callback>

However, the parameter within my method is ##0.

What is my mistake?

regards, rhodes
 

Mike

XenForo developer
Staff member
I'm not sure how you'd get ##0 in this, but it's worth noting that the params array is passed to your callback as an array -- it's not the individual arguments. This is how your callback gets called:

Code:
$output = call_user_func([$class, $method], $contents, $params, $this);

So the signature should be something like callback($contents, array $params, \XF\Template\Templater $templater).

Syntactically, I think you're probably ok, though I'd probably write the params as {{ [$thread.title] }} as it's cleaner, though I think they should ultimately be identical in this case.
 

rhodes

Active member
Thank's @Mike . I think I found my mistake. What I would need in my sidebar widget is the $pageTitle in a thread view context. However, it seems as if pageTitle is only available in template page_container, not in the sidebar widget template.
 
Top