Posted on: 02/16/04 06:50pm
By: Anonymous (include)
I need help trying to call a php include in a php block. This is the code that I have in HTML that works fine.
<!--#set var="cat" value="349" -->
<!--#set var="show" value="products" -->
<!--#set var="list_products" value="Y" -->
<!--#include virtual="avail_products_home.php" -->
Now, I tried putting that code into the following function in lib-commmon.php and tried calling it into a php block but all I got was a blank white page.
function phpblock_truthstore_items( $cat = 348, $show = both, $list_products = yes )
{
chdir("../../truthstore/cart/customer/"
;
include "avail_products_home.php";
}
Anyone have any ideas on how to get this code to work.
PHP Includes
Posted on: 02/16/04 10:57pm
By: vinny
To start with, I'd suggest replacing:
function phpblock_truthstore_items( $cat = 348, $show = both, $list_products = yes )
{
chdir("../../truthstore/cart/customer/");
include "avail_products_home.php";
}
--with this--
function phpblock_truthstore_items( $cat = 348, $show = both, $list_products = yes )
{
include "/absolute/path/truthstore/cart/customer/avail_products_home.php";
}
Also, make sure that "avail_products_home.php" doesn't pass any headers or have extra spaces before (both of which will cause problems).
Did you try looking at the source of the "blank page". If there was any output at all having that might help. Also, keep in mind that phpblocks are expected to return their output and not print it to the screen themselves (if you need to look into ob_start on php.net). Take a look at some of the example blocks in lib-custom.php for some simple examples.
-Vinny
PHP Includes
Posted on: 02/17/04 01:25am
By: Anonymous (adydas)
I think the probles is in fact that this include is meant to print out the results to an HTML page. I wouldn't know how to make it a return value. Would there be any way of just bypassing this and making it work like a regular html include.
PHP Includes
Posted on: 02/17/04 08:04am
By: vinny
No, there is no way to make it work like a regular HTML include.
Once again I suggest you look at the ob_start function on php.net (RTFM). You'll find instructions on how to buffer output and then you can return the output generated by your include.
-Vinny