array & list
| From: | Erik Torres | Date: | Wed, 02 May 2001 16:31:06 +0000 |
| Subject: | array & list | ||
| Groups: | php.general.es | ||
| Request: | Send a blank email to general-es+get-9522@lists.php.net to get a copy of this message | ||
Hi lista,
Primero mi presentacion y un saludo a todos en la
lista, mi nombre es Erik, soy cubano y trabajo como
web-master y web-developer.
Estoy trabajando en los templates para un sitio usando
PHPLib. Como es primera vez que hago esto me guio por
un articulo de David Orr que esta en www.php.net y se
titula: "Templates, the PHPLIB way."
El ultimo ejemplo del articulo no esta muy claro para
mi, ya en otra lista vi unas correciones hechas a este
ejemplo que no me funcionaron como esperaba y quisiera
que alguien me diera una mano con esto. El problema es
el siguiente:
Este es un codigo php que llama al template
mainpage.ihtml.
<?php
include "template.inc";
$t = new Template("/home/mydir/mytemplates/");
$t->set_file(array(
"mainpage" => "mainpage.ihtml",
"each_element" => "each_element.ihtml"));
/* aqui esta la correcion de la que hablo, en el
codigo original no venia esta linea */
$myArray = array( "One", "Two");
reset($myArray);
while (list($elementName, $elementValue) =
each($myArray)) {
// Set 'value' and 'name' to each element's value
and name:
$t->set_var("name",$elementName);
$t->set_var("value",$elementValue);
// Append copies of each_element:
$t->parse("array_elements","each_element",true);
}
$t->pparse("output","mainpage");
?>
Este es el template mainpage.ihtml:
<HTML>
Here is the array:
<TABLE>
{array_elements}
</TABLE>
</HTML>
Y este es el template each_element.ihtml:
<TR>
<TD>{name}: {value}</TD>
</TR>
El resultado es:
Here is the array:
0: One
1: Two
Ahora, como hago para que un archivo
each_element.ihtml de la forma:
<TR>
<TD>{name}: {value1}: {value2}: {value3}</TD>
</TR>
me funcione para tener un resultado como este:
Here is the array:
0: One1: One2: One3
1: Two1: Two2: Two3
Muchas gracias,
Erik
__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/