Adding external HTML or PHP into a template

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • calgarypuck
    Member
    • Sep 2005
    • 73
    • 3.5.0 Pre-Release

    Adding external HTML or PHP into a template

    Ok a little new to this still. As I understand it, if I wanted to execute some php code at a specific location that location is a hook. And to add that code, that's a plugin.

    I guess the question is can I add a hook to the footer? I have a few external HTML and PHP code that I want to include in the wrapper around the board, and if I understand correctly I can't put the raw code in the header or footer templates.

    EDIT: And for the external HTML, I don't want to have to edit the template directly to change the small chunk of HTML, in an external file is better in my case.

    Or am I totally on the wrong track?

    TIA
    Last edited by calgarypuck; Sat 3 Dec '05, 4:46pm.
  • feldon23
    Senior Member
    • Nov 2001
    • 11291
    • 3.7.x

    #2
    Templates were not designed for this. Allowing templates to execute meaningful PHP code might be a security risk and I am sure there were performance reasons for not allowing this as well.

    Inserting PHP code or an external HTML file is handled by Plug-ins.

    AdminCP -> Plugin System -> Add New Plugin

    Choose 'global_start' as the Location/Hook then paste this code:

    Code:
    ob_start();
    include_once('./other.php');
    $otherphp = ob_get_contents();
    ob_end_clean();
    where other.php is the name of your php or html file (header.html, special_content.html, mystuff.php, etc.). You can rename $otherphp, the variable that the file is loaded into, to something else in case you intend to read multiple files and embed them in your site.

    Then add the $variable to the template you wish that content to appear in.

    For instance, I create a plugin "Banner Ads":
    Code:
    ob_start();
     include_once('./banner_ad_code.php');
     $banner_ad_code= ob_get_contents();
     ob_end_clean();
    then I edit my navbar template and add $banner_ad_code wherever I want and the contents of banner_ad_code.php will be executed and pasted there.
    Last edited by feldon23; Sat 3 Dec '05, 6:58pm.

    Comment

    • calgarypuck
      Member
      • Sep 2005
      • 73
      • 3.5.0 Pre-Release

      #3
      Excellent! That's exactly what I need, many thanks for your help.

      Comment

      widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
      Working...