XF 2.0 Simple "Hello World" Xenforo 2.0 Problem

hutch2323

New member
Hello,

I'm new to Xenforo 2.0 and clearly there are some changes. I'm simply trying to get a "Hello World" string to be written on my node page, from a .php file. Currently, I have a Test.php file located in the \src\addons\XFP directory. This is the code used in Test.php:

PHP:
<?php

namespace XFP;

class Test{
   
    public static function getHtml(){
         $output = 'Hello World';
         return $output;
    }
}

?>

On the node page, under the Template HTML section, I have the following:

HTML:
<xen:callback class="\XFP\Test" method="getHtml"></xen:callback>

Finally, the PHP callback is:

XFP\Test::getHtml

However, when I save and go to the node on my website, "Hello World" is nowhere to be found (see below). What am I doing wrong? Am I missing something in the .php file or under the Template HTML section?
NoOutput.webp
 
It all starts with simple Hello World problem. Be sure to share with us how you get on with other things. I'm interested in learning that too.
 
Brand new to Xenforo (vBulletin convert) and Im trying to figure out how to get custom PHP into xenforo (I have a PHP header across the rest of my website that I need to include at the top of every Xenforo page). I've been reading old threads here for a few hours and looking at the manual.

The above example is enough to follow (and I've swapped the <xen> tag for <xf> as suggested but I get

"Callback \XFP\Test::getHtml is invalid (error_invalid_class)."

I've placed test.php in public_html/forum/src/addons/XFP (xenforo is installed in /forum)

I've put

HTML:
<xf:callback class="\XFP\Test" method="getHtml"></xf:callback>

into the page_container template just below the body tag. Obviously Xenforo isn't finding test.php and I'm missing a step somewhere to help it locate the method or should I put the XF tags somewhere else?

Any help appreciated.
 
Have you placed the Test.php file in the src/addons/XFP directory?

Double check the directory, file, and namespace names match (including capitalisation).

It works for me on my local using a directory of CTA and adding the callback to the PAGE_CONTAINER template.

PHP:
<?php

namespace CTA;

class Test{
 
    public static function getHtml(){
         $output = 'Hello World';
         return $output;
    }
}

?>

1622482129578.png

1622482148407.png

1622482067894.png
 
@crondoc, i guess you're XF installation running under Linux and using any ext-filesystem.
ext filesystem is case sensitive. You're noticed in your post file name test.php, but you try reference then as Test class.
 
Hey gang, I was just searching for basic info on running a PHP script in a sidebar and wanted to thank you guys for this thread. It was exactly the info I needed.

Mike
 
Back
Top Bottom