1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP code in template?

Discussion in 'XenForo Development Discussions' started by Mufasa, Aug 12, 2013.

  1. Mufasa

    Mufasa Active Member

    Im looking to add a php code here:
    [​IMG]
    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!
     
  2. Jeremy

    Jeremy XenForo Moderator Staff Member

  3. JulianD

    JulianD Well-Known Member

    Use the <xen:callback> tag. It is like running php on the template itself.
     
  4. Mufasa

    Mufasa Active Member

    Its a status code for server. Can i use xen:include? Does that work the same?

    Can u explain how to and what it does? Lol
     
  5. Jeremy

    Jeremy XenForo Moderator Staff Member

    No, xen:include is for including templates.
     
  6. Mufasa

    Mufasa Active Member

    Ok, so I'm assuming i need callback, can u explain how please? Thats something not explained on that link :)
     
  7. Jeremy

    Jeremy XenForo Moderator Staff Member

  8. AndyB

    AndyB Well-Known Member

    The xen:callback should work perfect for what you want to do. Here's an example:

    http://xenforo.com/community/resources/xen-callback-tag.2027/
     
  9. Mufasa

    Mufasa Active Member

  10. tyteen4a03

    tyteen4a03 Well-Known Member

    Code please?
     
  11. Mufasa

    Mufasa Active Member

    PHP:
    <?php
    $ip 
    "xxx.xxx.xxx.xxx";
    $port "xx";
    $online = @fsockopen$ip$port$errno$errstr200);
    if(
    $online >= 1) {
    echo 
    '<a href="#"><img src="/forum/serverstatus/serveronline.png"></a>';
    }
    else {
    echo 
    ' <a href="#" ><img src="/forum/serverstatus/serveroffline.png"</a>,';
    }
    ?>
     
  12. AndyB

    AndyB Well-Known Member

    Using the example I posted in post #8, were you able to output "Hello World" ??
     
  13. JulianD

    JulianD Well-Known Member

    make sure your method starts with get, is, has, render, view, return, print, show or display.

    Example: getHtml
     
  14. Mufasa

    Mufasa Active Member

    Thats a negative sir.
    Code:
    Could not execute callback Example_Scripts_index::getHtml() - Not callable.
     
  15. AndyB

    AndyB Well-Known Member

    Did you follow the example exactly?

    Do you get an error message?
     
  16. Mufasa

    Mufasa Active Member

    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$errstr200);
    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>
     
  17. Mufasa

    Mufasa Active Member

    followed exactly, exact error message as posted above,
     
  18. Jeremy

    Jeremy XenForo Moderator Staff Member

    Where are you saving the file?
     
  19. JulianD

    JulianD Well-Known Member

    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.
     
  20. Mufasa

    Mufasa Active Member

    forum/Library/Example/Scripts/serverstatus.php

    All is matched.
     

Share This Page