XF 2.0 xf2 callback. insert php in template.

Krel

Member
Hello.
This code worked with xf1.x.
Code:
<xen:callback class="Quotes_Index" method="getHtml"></xen:callback>

After upgrade to 2.0 this code doesn't work.
Please tell me how change this code for xenforo 2? I'd like to insert php in my template xf2.
 
Not works.
I put in library/Quotes/Index.php
Code:
<?php
class Quotes_Index
{
public static function getHtml()
{
//include '\library\Example\Srv_Status.php';
include '/var/www/html/quotes.php';
return $output;
}
}
?>

Then I tryed insert in template
Code:
<xf:callback class="Quotes_Index" method="getHtml"></xf:callback>

But it does't work. What i do wrong? :(

Error is: Callback Quotes_Index::getHtml is invalid (error_invalid_class).
 
Could you please google for me some manuals? I really can't understand what to do and what to change.
 
Ok. That's my solution:

1. Create dir at /src/addons/Quotes/
2. put there file touch /src/addons/Quotes/Quotes_Index.php
Code:
<?php
namespace Quotes;
class Quotes_Index
{
your code here
}
3. In template insert
Code:
<xf:callback class="\Quotes\Quotes_Index" method="getHtml"></xf:callback>

It works well.
 
Ok. That's my solution:

  1. Create dir at /src/addons/Quotes/
  2. put there file touch /src/addons/Quotes/Quotes_Index.php
Code:
<?php
namespace Quotes;
class Quotes_Index
{
your code here
}
3. In template insert
Code:
<xf:callback class="\Quotes\Quotes_Index" method="getHtml"></xf:callback>

It works well.
I followed exactly like yours, but still getting Error is: Callback Quotes_Index::getHtml is invalid (error_invalid_class). error message, any clue? 🤷‍♂️
 
Probably there is a error in your php code. You need to post contents of your file.
 
Here's my src/addons/PageServed/Index.php (capital i)
Code:
<?php
namespace PageServed;
class PageServed_Index
{
Test html
}
www@svr:/src/addons/PageServed$
And this is what I use on my template:
Code:
<xf:callback class="\PageServed\Index" method="getHtml"></xf:callback>
 
That's not valid php code. You need to add function inside it:
Code:
<?php
namespace PageServed;
class Index
{
  public static function getHtml()
  {
    return 'Test html';
  }
}
Also class name is wrong. It should match file name.
 
Top Bottom