Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Error after including php script in .tpl file

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
goalsurfer
Smarty Rookie


Joined: 30 Oct 2009
Posts: 29
Location: Brussels

PostPosted: Wed Dec 16, 2009 11:58 pm    Post subject: Error after including php script in .tpl file Reply with quote

The script I included works perfectly in common php and I suppose also the inclusion is all right as some parts of the script are working fine. I did it as follows: {php}
include("path_to_file");
{/php}

This is the error message:
"Warning: Invalid argument supplied for foreach() in ... [here follow path to the script file] ... in line ..."

On the line of error there is in the php script:
"foreach ($photos as $key => $value) {"

Please can somebody help me out of this, normally you may not change the script and I also wonder if that's the way to find the solution.

Thanks.
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Dec 17, 2009 2:41 pm    Post subject: Reply with quote

It is because the variable you are trying to loop over is not iterable (not an array, or empty)

Why are you trying to include PHP in the template? Just assign the tpl var and use {foreach}
Back to top
View user's profile Send private message Visit poster's website
goalsurfer
Smarty Rookie


Joined: 30 Oct 2009
Posts: 29
Location: Brussels

PostPosted: Thu Dec 17, 2009 4:03 pm    Post subject: Error after including php script in .tpl file Reply with quote

I tried it with next in index.php:

$photobook = array();
$smarty->assign('myArray', $photobook);

but that seems too complicate because $photobook exists of many different cases. It is a script only existing in one file.

Meanwhile I'm trying out phpAutoGallery but whereas the admin function
is working I don't get anything at all in the .php file. I can't even get an ordinary image file in a directory on the screen. I don't know if you are familiar with phpAutoGalery? It is a sourceforge.net project where the last support input is from some years ago. Phreakpic I can't use as I'm not intended to install a forum.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP