Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

{html_table} and assoc. arrays

Post new topic   Reply to topic    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
Smarty Rookie

Joined: 08 Jul 2003
Posts: 11

PostPosted: Wed Jul 09, 2003 12:06 am    Post subject: {html_table} and assoc. arrays Reply with quote

I've looked around and didn't see anyone else talking about this, though I can't believe nobody else has run into this problem before.

When the loop argument is set to an associative array everything runs as expected except that the outputted tds are blank.

Since php can normally handle an associative array as if it's a normal array by using numerical indexes, I figure this must be a bug....

In any case this doesn't seem to be mentioned in the documentation.
Back to top
View user's profile Send private message Send e-mail
Smarty n00b

Joined: 09 Jul 2003
Posts: 3
Location: Portland, Oregon

PostPosted: Fri Jul 11, 2003 4:01 pm    Post subject: test case Reply with quote

I don't think this is limited to associative arrays. I have the same problems with Smarty 2.5.0 and php 4.3.2 and I think 4.1.x also.

Here's a test case. Template first:

{html_table loop=$doremi td_attr=$doremi_td}
{html_table loop=$fasola td_attr=$fasola_td}
{html_table loop=$tido td_attr=$tido_td}

Now the php:

define ('SMARTY_DIR', '/usr/local/lib/php/Smarty');
$smarty = new Smarty;
$smarty->assign('doremi', array ('do', 're', 'mi'));
/* Smarty messes up the order of tido_td */
$smarty->assign('fasola', array ('fa', 'so', 'la'));
/* Smarty ignores tido_td, see output below */
$smarty->assign('tido',array ('ti', 'do'));

And the output:

/usr/local/bin/php scale.php
<table border="1">
<tr >
<td bgcolor="#cococo">do</td>
<td bgcolor="#ffffff">re</td>
<td bgcolor="#cococo">mi</td>
<table border="1">
<tr >
<td bgcolor="#ffffff">fa</td>
<td bgcolor="#cococo">so</td>
<td bgcolor="#ffffff">la</td>
<table border="1">
<tr >
<td >ti</td>
<td >do</td>
<td >&</td>

The <td >ti</td> and <td >do</td> should be <td bgcolor=#cococo>ti</td> and <td bgcolor=#cococo>do</td> respectively. Minor changes in the code tweak this problem. If tido_td is an array of two elements, it works. Removing either doremi or fasola from both the php and the tpl file makes everything work fine too. As does setting tido's td_attr directly in the template rather than in the php script. And as I mentioned in the comments in the code, bgcolor tags for fasola are incorrectly ordered.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Bugs 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