PHP in template error

Discuss PivotX 2.0.x here. Non-PivotX related discussions go in The Drain.

PHP in template error

Postby Justice » Thu Dec 29, 2011 10:29 am

Hi, i want to include in _sub_sidebar.tpl simple php ad rotator, but it shows me "Smarty error: unable to read resource: "(randomad.php)": 512"

Include with [[ include file="(randomad.php)" ]] in tpl file.
randomad.php have following code:
Code: Select all

$adfile = "ads.txt";
$ads = array();

$fh = fopen($adfile, "r");
while(!feof($fh)) {

  $line = fgets($fh, 10240);
  $line = trim($line);
  if($line != "") {
   $ads[] = $line;

$num = count($ads);
$idx = rand(0, $num-1);

echo $ads[$idx];

php in templates is allowed. any suggestions? how to solve this problem?
Posts: 51
Joined: Wed Nov 23, 2011 10:18 pm

Re: PHP in template error

Postby Harm10 » Thu Dec 29, 2011 5:24 pm

Did you check the documentation?
The file location should be relative to the templates folder.
I guess you also remembered to switch on the setting for php in templates? allow_php_in_templates
Quality is in the detail of things............

Want to change or update your PivotX site? Mail or PM me!
I can also convert your site to a Wordpress site!
Posts: 2011
Joined: Wed Jun 17, 2009 9:37 am
Location: Somewhere in The Netherlands (aka Holland)

Re: PHP in template error

Postby hansfn » Thu Dec 29, 2011 8:40 pm

[[ include file="(randomad.php)" ]]

Why the parenthesis? Anyway, as far as I remember you can't run PHP code by including a file it like that. The best approach is to turn the file into a proper PivotX extension. The second best choice is to use the a php template block:

Code: Select all
Posts: 3282
Joined: Sun Nov 25, 2007 7:48 pm
Location: Molde, Norway

Return to 2.x Discussion

Who is online

Users browsing this forum: No registered users and 1 guest