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

Including Files with the same name

 
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
stfuji
Smarty Rookie


Joined: 12 Jan 2004
Posts: 5

PostPosted: Mon Jan 12, 2004 5:13 pm    Post subject: Including Files with the same name Reply with quote

Hi,

I am a new Smarty - er so hopefully this isn't a answered question:

I have a template page that uses a loop ie:

Code:

{foreach from=$page_elements item=page_element}
   {include file=$page_element}
{/foreach}


on my smarty page I am using a loop to push an array element to create an unbounded array of template files to be included ie

Code:


//  sql query of some variety using phpBB db classes
$sql = "SELECT * FROM employee"

if ( !($result = $db->sql_query($sql)) {
     die("Bad db call");
}


foreach ($result as $employee) {

     array_push($page_element, 'edit.tpl');
     array_push($employees, $employee);

}

$smarty->assign('page_elements', $page_elements);



the edit.tpl file has some includes as well i.e.

Code:


<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td>{include file="elements/id.tpl"}</td>
</tr>
<tr>
<td>{include file="elements/name.tpl"}</td>
</tr>
<tr>
<td>{include file="elements/address.tpl"}</td>
</tr>
<tr>
<td>{include file="elements/numbers.tpl"}</td>
</tr>
</table>



the problem is the page will only list the edit table once so since there are say 5 employees returned in my recordset I should have 5 tables generated from the smarty foreach loop including each iteration of the included file.

If the edit.tpl file does not include any of the

{include file=}

smarty directives the foreach loop will print the blank table...

Is this a bug or am I doing something incorrectly?

Thanks ahead,
Geoffrey
Back to top
View user's profile Send private message
stfuji
Smarty Rookie


Joined: 12 Jan 2004
Posts: 5

PostPosted: Tue Jan 27, 2004 4:58 pm    Post subject: Reply with quote

No one has any clue?
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Tue Jan 27, 2004 5:03 pm    Post subject: Reply with quote

Code:
 foreach ($result as $employee) {
 
      array_push($page_element, 'edit.tpl');
      array_push($employees, $employee);
 
 }
 
 $smarty->assign('page_elements', $page_elements);


you push into "$page_element" but assign "$page_elements" (note the 's').

use 'error_reporting(E_ALL)' in php to prevent such typos getting you.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
stfuji
Smarty Rookie


Joined: 12 Jan 2004
Posts: 5

PostPosted: Tue Jan 27, 2004 6:24 pm    Post subject: Reply with quote

Yup,

Much obliged for the help. Thanks for the error reporting hint too!

-Geoff
Back to top
View user's profile Send private message
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