XF 2.1 Display a thread post in xenforo's page

Wildcat Media

Well-known member
Would I still need this if ($reply instanceof \XF\Mvc\Reply\View) { } loop? I've tried it both ways.

This is what I'm at right now (template is set up properly as xxxx_post_in_page_showpost):

PHP:
<?php

namespace XXXX\PostsOnPages;

class xxxxProviders
{
    public static function getData(
        $contents,
        array $params,
        \XF\Template\Templater $templater
    ) {
       
        if ($reply instanceof \XF\Mvc\Reply\View) {
            if (!$threadId) {
                return;
            }

            $thread = \XF::app()->find('XF:Thread', $threadId, ['FirstPost']);
            $post = $thread->FirstPost;

            return $templater->renderTemplate('public:xxxx_post_in_page_showpost', [
                'thread' => $thread,
                'post' => $post
            ]);
        }
    }
}

I'm calling it like this in the page node template:

<xf:callback class="\XXXX\PostsOnPages\xxxxProviders" method="getData" params="['42307']"></xf:callback>

No errors but no output.

I'm familiar with the "dump" function in a template (like {{ dump($xf) }} or some other variable).
 

Lukas W.

Well-known member
$reply is an undefined variable in your code, so that condition will always be false (and likely throw a warning).
 

Wildcat Media

Well-known member
$reply is an undefined variable in your code, so that condition will always be false (and likely throw a warning).
No warning or error, but even when it's removed, I have no output. That was left over from:

Code:
    public static function getData(
        \XF\Pub\Controller\AbstractController $controller,
        \XF\Mvc\Reply\AbstractReply &$reply
        ) {

...when I was using the callback from the page node vs. using xf:callback in the page node template.
 

Wildcat Media

Well-known member
$threadId isn't set either in your code, so it returns empty in the check right after.
I must have lost this line somewhere when I was pasting. 😁 I had $threadId = $params[0]; just prior to if($threadId) ....

Can't believe I missed that. I was staring at it too long last night. Thanks! That got it working. And thanks to @Jeremy P for helping me push this in the right direction. 🍻
 
D

Deleted member 91401

Guest
@Rudy I'm looking at creating a custom php page but not to display threads, just to display a static html form with some php magic on the same page, how could I use your code to achieve this? would be so grateful for any help
 

Wildcat Media

Well-known member
@Rudy I'm looking at creating a custom php page but not to display threads, just to display a static html form with some php magic on the same page, how could I use your code to achieve this? would be so grateful for any help
Probably best to start another thread about it--I'm sure someone more familiar with the system could help out.
 
Top