|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
stfuji Smarty Rookie
Joined: 12 Jan 2004 Posts: 5
|
Posted: Mon Jan 12, 2004 5:13 pm Post subject: Including Files with the same name |
|
|
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 |
|
stfuji Smarty Rookie
Joined: 12 Jan 2004 Posts: 5
|
Posted: Tue Jan 27, 2004 4:58 pm Post subject: |
|
|
No one has any clue? |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Tue Jan 27, 2004 5:03 pm Post subject: |
|
|
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 |
|
stfuji Smarty Rookie
Joined: 12 Jan 2004 Posts: 5
|
Posted: Tue Jan 27, 2004 6:24 pm Post subject: |
|
|
Yup,
Much obliged for the help. Thanks for the error reporting hint too!
-Geoff |
|
Back to top |
|
|
|
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
|