PHP code in template?

Mufasa

Active member
Im looking to add a php code here:
lu3MDqM.png

i have tried the normal php include code, that doesnt work. i tried just putting the code where i need it, that didnt work. i searched around, nothing i found related to this.

Template im editing: node_catagory_level_1

if there is a way to include the file into that spot, could you please tell me? lol.

Thanks!
 
What's the PHP attempting to do?

There's a start to template syntax documentation that may be useful for you:
http://xenforo.com/community/resources/template-syntax-xenforo-tags.2122/

But, PHP code cannot be placed directly in templates.
Its a status code for server. Can i use xen:include? Does that work the same?

Use the <xen:callback> tag. It is like running php on the template itself.
Can u explain how to and what it does? Lol
 
Code please?

PHP:
<?php
$ip = "xxx.xxx.xxx.xxx";
$port = "xx";
$online = @fsockopen( $ip, $port, $errno, $errstr, 200);
if($online >= 1) {
echo '<a href="#"><img src="/forum/serverstatus/serveronline.png"></a>';
}
else {
echo ' <a href="#" ><img src="/forum/serverstatus/serveroffline.png"</a>,';
}
?>
 
make sure your method starts with get, is, has, render, view, return, print, show or display.

Example: getHtml
The code to include
PHP:
<?php
class Example_Scripts_index {
  public static function getHtml() {
    include '/forum/serverstatus/online.php';
    return $output;
  }
}
?>
The inluded file:
PHP:
<?php
$ip = "xxx.xxx.xxx.xxx";
$port = "xx";
$online = @fsockopen( $ip, $port, $errno, $errstr, 200);
if($online >= 1) {
echo '<a href="#"><img src="/forum/serverstatus/serveronline.png"></a>';
}
else {
echo ' <a href="#" ><img src="/forum/serverstatus/serveroffline.png"</a>,';
}
?>
The callback code:
Code:
<xen:callback class="Example_Scripts_index" method="getHtml"></xen:callback>
 
The code to include
PHP:
<?php
class Example_Scripts_index {
  public static function getHtml() {
    include '/forum/serverstatus/online.php';
    return $output;
  }
}
?>
The inluded file:
PHP:
<?php
$ip = "xxx.xxx.xxx.xxx";
$port = "xx";
$online = @fsockopen( $ip, $port, $errno, $errstr, 200);
if($online >= 1) {
echo '<a href="#"><img src="/forum/serverstatus/serveronline.png"></a>';
}
else {
echo ' <a href="#" ><img src="/forum/serverstatus/serveroffline.png"</a>,';
}
?>
The callback code:
Code:
<xen:callback class="Example_Scripts_index" method="getHtml"></xen:callback>

I guess you have your callback class in library/Example/Scripts/index.php. Pay close attention to upper and lower case letters, they do matter.
 
Top Bottom