I'm trying to include a comment system in my template.
This is the system: http://plohni.com/wb/content/php/Script___advanced_comment_system.php

But, I'm having problems "including" the index.php file in my template (layouts/main_template.html).
I've tried using

  {include_php file="comments/index.php"}

I get nothing output from comments/index.php at all, no errors are shown, even though I have display_errors set to true. No errors in my PHP error log, either.

I cannot convert comments/index.php file to a template easily. You'd have to look at the code to see why. I've tried using this code in my /index.php (not comments/index.php), too, but it shows the PHP code instead of the rendered HTML:

  $data = $smarty->fetch("content/index.html");
  $smarty->assign("content", $data);
  $comments = file_get_contents('comments/index.php');
  $smarty->assign("comments", $comments);
  $smarty->display("layouts/main_template.html");

One other thing that I've tried with no success is this, from /index.php:

$data = $smarty->fetch("content/index.html");
$smarty->assign("content", $data);
$smarty->display("layouts/main_template.html");
include("comments/index.php");
  // included code from main_template.html below the place I want to have the comments here
echo '  </body>  ';
echo '</html>';

I understand that {include_php} is pretty much deprecated from Smarty, so what am I supposed to do, here?

Any other suggestions?

    mrbaseball34;10966183 wrote:

    I get nothing output from comments/index.php at all, no errors are shown, even though I have display_errors set to true. No errors in my PHP error log, either.

    Is you error level set to -1?
    Otherwise, perhaps smarty debugging will help you in this regard.
    I've never bothered with smarty's debugging functionality, since the PHP error reporting have always been sufficient for me (and I do get to see errors). In this case I'd expect it to either work or show me

    Warning: smarty error: file:filename.php is not readable

    Probably a silly question but do the include_php included file actually produce output, i.e. contain echo, print, print_r or var_dump?

    mrbaseball34;10966183 wrote:

    I've tried using this code in my /index.php (not comments/index.php), too, but it shows the PHP code instead of the rendered HTML:

      # why first fetch a template...
      $data = $smarty->fetch("content/index.html");
      # ... and then assign it to a smarty variable for use in another template,
      $smarty->assign("content", $data);
      # ... when you, inside that template could
      {include file="template.tpl"}
    
      # this is read without PHP parsing
      $comments = file_get_contents('comments/index.php');
      # in the same way this works (except not from file)
      $comments = 'echo "stuff";';
      # If you want to have it parsed as PHP code, your options are
      require 'comments/index.php';
      include 'comments/index.php';
    
    mrbaseball34;10966183 wrote:

    I understand that {include_php} is pretty much deprecated from Smarty, so what am I supposed to do, here?

    Just like the documentation for {include_php} states, you are supposed to use plugins. By default, they should go into SMARTY_DIR/plugins. The file name should be on the specified form and the insert or function plugin function also needs to be on the specified form.

      For some reason it began working and I have everything working as expected now.
      I was making some heavy modifications to the system so it must have been one that I made.
      I re-downloaded it and started over going a little at a time until I got it working like I want.

      Thanks for looking at this.

        Write a Reply...