Template Modification: PHP Callback does not work

rellek

Well-known member
Let's just assume you want to clear the template 'header' with "XenForo rocks" using a PHP callback in a template modification... I think this doesn't work.

Here's what I entered:
Template: header
Modification Key: removeheader
Description: test
Search Type: PHP Callback
Find: /.+/is
Replace: rellek_TMSTest::myMethod

and there's a file, ./library/rellek/TMSTest.php which looks like this:
PHP:
<?php

class rellek_TMSTest {


     public function myMethod(array $args) {

          return 'XenForo rocks';

     }

}

This won't work.

It doesn't match anything when I click "Test Modification" and has the status 0/0/1 in the TM list.

If I change PHP callback to Regular Expression, It shows me that it matches everything and replaces this with my callback name.

Question is, is this a bug or am I doing something wrong?
 
the method needs to begin with

  • get
  • is has
  • render
  • view
  • return
  • print
  • show
  • display
and it needs to be static
 
Template modifications don't requite the method prefix (xen:callback does).
 
  • Like
Reactions: Dan
D'oh! Thanks.

But why is it callable then? I mean, I did look into the XF source code and it does check if it is callable...?
 
Why is it callable after you make it static? Because the system doesn't create an instance of your class to run your code, so it needs to be static to allow that to work.
 
@Jeremy
No it was callable (according to that function is_callable) before I made it static. I saw in the source code that XF checks if a method is callable and throws an error if not. But @xf_phantom answered this, it seems to be a PHP flaw then.
 
Top Bottom