XF 1.5 Send var from add-on to template


New member
Hi everybody,

I tried to create an add-on (inspired by SimilarThreads from @AndyB.
I needed to generate a list of similar blog post (WordPress).

Everything work nice excepted one thing, i can't use my custom vars in my template.

So, what i did :

  1. Create an add-on in ACP
  2. Create an event listener on load_class_controller
  3. On my listener, i add my controller class
  4. My class is working like ControllerPublic_Thread than SimilarThreads add-on
  5. At the end i add my params to $parent->params
  6. On my template, i test : {xen:helper dump, $similarBlogs} - It's always == null
What do you need to put me on the path ?

Thank you very much.

PS : I'm sorry my english is not very good.


New member
Hmm i don't return responseView()

Edit: Just in case, my goal is to send an array to my public variables, to use it in a custom sidebar in thread view

Here is my code :

* Copy from Andy SimilarThreads
class Wri_SimilarBlog_ControllerPublic_Thread extends XFCP_Wri_SimilarBlog_ControllerPublic_Thread {
    public function actionIndex() {
        // get parent
        $parent = parent::actionIndex();
        // return parent action if this is a redirect or other non View response
        if (!$parent instanceof XenForo_ControllerResponse_View)
            return $parent;
        // return parent action if empty thread_id
        if (empty($parent->params['thread']['thread_id']))
            return $parent;
         * TODO My custom function here that work outside XenForo
        // Sample return
        $similarBlog = [
                'title' => "My first blog post",
                'link' => "https://example.com/blog/post1"
                'title' => "My second similar blog post",
                'link' => "https://example.com/blog/post25"
                'title' => "Another similar blog post",
                'link' => "https://example.com/blog/post985"
        // prepare viewParams
        if ($parent instanceOf XenForo_ControllerResponse_View)
            $viewParams['similarBlog'] = $similarBlog;
            // add viewParams to parent params
            $parent->params += $viewParams;
        // return parent
        return $parent;

And this is my template :

{xen:helper dump, $similarBlog}
<xen:if is="{$similarBlog}">
        <xen:foreach loop="$similarBlog" value="$article">
            <li><a href="$article.link">$article.title</a></li>
$similarBlog is null in this case

Edit 2: When i use {xen:helper dump, $similarBlog} in thread_view template, it works
But not in my custom template wich is load with ad_sidebar_bottom template modification

I will try with responseView, i saw some others files with this return. Thanks for this indication :)
Last edited: