Well , how do I pass those parameters?Yes in theory this is possible.
You can pass parameters from the event listener to your template via a hook.
If you need any specific help, let me know.
public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
{
if ($hookName == 'message_user_info_avatar'){}}
$hookParams['stuff'] = $stuff;
Right now , I have this:I have no idea how you're including the PHP file, what the variables look like, whether the PHP file itself contains HTML to render stuff.
It's all a bit too vague to answer with much detail.
That being said, typically your template hook would look like this (bare bones)
Rich (BB code):public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template) {
if ($hookName == 'message_user_info_avatar'){}}
How you include your PHP file, and what you want to achieve, I have no idea. But if that PHP file contains an array of data called $stuff (for example) then you could pass that to the hook like this:
Rich (BB code):$hookParams['stuff'] = $stuff;
You would now be able to use {$stuff} in your template.
You can verify the "stuff" has been passed to the template by dumping it using:
{xen:helper dump, $stuff}
This would output the raw data from the array in your template.
But again, this is all very vague as I'd probably need to see all of your code and work out what you're trying to achieve to be more accurate/specific. But hopefully what I've said so far will help.
<?php
class Stuff_Listener
{
public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template){if ($hookName == 'message_user_info_avatar'){include 'your_stuff.php';// Example: let's assume $stuff is a variable in your_stuff.php$hookParams['stuff'] = $stuff;$params = $template->getParams();$params += $hookParams;$contents .= $template->create('your_template', $params);}}}
What do I put in $hookParams['stuff'] = $stuff;[That really isn't any less vague than you already have been...
If you can paste some example code from your class and code event listener that would be useful.
I imagine it should look something like this:
- You've created an add-on in the Admin CP. Let's pretend it's called "Stuff".
- You've created a Listener.php (or similar name) in your library/Stuff folder
- That should look like this:
Rich (BB code):<?php class Stuff_Listener {
public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template){if ($hookName == 'message_user_info_avatar'){include 'your_stuff.php';// Example: let's assume $stuff is a variable in your_stuff.php$hookParams['stuff'] = $stuff;$params = $template->getParams();$params += $hookParams;$contents .= $template->create('your_template', $params);}}}With that code example above, theoretically in the message_user_info_avatar section you should now see a load of data being dumped which should hopefully be the data from the your_stuff.php script.
- You should have created a Code Event Listener in the Admin CP with event Template Hook, callback being: Stuff_Listener::templateHook
- (Example) Created a template called your_template in the Admin CP .
- In your_template type (for demo purposes) {xen:helper dump, $stuff}
Hope that helps.
Thanks! I have more questions if you don't mind. I have this code , this is the php file which is included.$hookParams is the array that stores all of the parameters that are available to the template hook.
$hookParams['stuff'] = $stuff;
...is adding an additional parameter to the template hook called stuff. Its contents is the PHP variable $stuff.
In my example $stuff is whatever variable you need to pull from your included PHP script.
Once you've got that, you should be able to use {$stuff} in your template. My suggestion initially is to use {xen:helper dump, $stuff} in your template for testing purposes.
If this still isn't working then I can't help you any further unless you post your existing code, and a more detailed explanation of what you're trying to achieve.
<?php
class Steam_Rep_Rep {
// cURL Variable
private $ch = null;
public function __construct() {
// Setup cURL
$this->ch = curl_init();
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->ch, CURLOPT_TIMEOUT, 4);
}
public function getUserInfo($steamrep_id) {
// cURL
curl_setopt($this->ch, CURLOPT_URL, "http://steamrep.com/api/beta/reputation/76561197971691194?json=1");
$result = curl_exec($this->ch);
$xml = json_decode($result);
if(!empty($xml->steamrep->reputation)) {
return array(
'rep' => $xml->steamrep->reputation,
);
} else {
return array(
'rep' => "No reputation found",
);
}
}
}
$steam = new Steam_Rep_Rep();
$rep = $steam->getUserInfo('76561197971691194');
echo $rep['rep'];
?>
<?php
class Steamrep_Rep_Rep {
public static function includePhpFile($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
{
if($hookName == 'message_user_info_avatar')
{
ob_start();
require_once('php_include.php');
$contents .= ob_get_contents();
ob_end_clean();
}
}
}
?>
We use essential cookies to make this site work, and optional cookies to enhance your experience.