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
volkris
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
pdxchris
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:
Code:

templates/scale.tpl:
<html>
<head>
</head>
<body>
                                                                               
                                                                               
{html_table loop=$doremi td_attr=$doremi_td}
{html_table loop=$fasola td_attr=$fasola_td}
{html_table loop=$tido td_attr=$tido_td}
                                                                               
                                                                               
</body>
</html>


Now the php:
Code:

scale.php:
<?php
define ('SMARTY_DIR', '/usr/local/lib/php/Smarty');
ini_set("include_path",".:/usr/local/lib/php/Smarty");
require('Smarty.class.php');
$smarty = new Smarty;
                                                                               
                                                                               
$smarty->assign('doremi', array ('do', 're', 'mi'));
$smarty->assign('doremi_td',array('bgcolor="#cococo"','bgcolor="#ffffff"'));
                                                                               
/* Smarty messes up the order of tido_td */
                                                                               
$smarty->assign('fasola', array ('fa', 'so', 'la'));
$smarty->assign('fasola_td',array('bgcolor="#cococo"','bgcolor="#ffffff"'));
                                                                               
/* Smarty ignores tido_td, see output below */
                                                                               
$smarty->assign('tido',array ('ti', 'do'));
$smarty->assign('tido_td',array('bgcolor="#cococo"'));
                                                                               
                                                                               
$smarty->display('scale.tpl');
?>


And the output:
Code:

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


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