aquí está el código:
{section name=k loop=$obj->mProduct.attributes} {* Generate a new select tag? *} {if $smarty.section.k.first || $obj->mProduct.attributes[k].attribute_name !== $obj->mProduct.attributes[k.index_prev].attribute_name} {$obj->mProduct.attributes[k].attribute_name}: <select name="attr_{$obj->mProduct.attributes[k].attribute_name}"> {/if} {* Generate a new option tag *} <option value="{$obj->mProduct.attributes[k].attribute_value}"> {$obj->mProduct.attributes[k].attribute_value} </option> {* Close the select tag? *} {if $smarty.section.k.last || $obj->mProduct.attributes[k].attribute_name !== $obj->mProduct.attributes[k.index_next].attribute_name} </select> {/if} {/section}Sigo recibiendo más de dos declaraciones selectas.
POR FAVOR AYUDA...

Espero:
Color:<select name="attr_Color"> <option value="White">White</option> <option value="Black">Black</option> //.... </select> Size:<select name="attr_Size"> <option value="XL">XL</option> <option value="L">L</option> //.... </select>Sin embargo, obtengo varias etiquetas de selección en lugar de solo dos:
Color: <select name="attr_Color"> <option value="White">White</option> </select> Color: <select name="attr_Color"> <option value="black">black</option> </select> //... Size: <select name="attr_Size"> <option value="l">l</option> </select> Size: <select name="attr_Size"> <option value="XL">XL</option> </select> //...Puedo resolver esto bastante bien con PHP, sin embargo, Smarty 3 está demostrando ser terco. Ustedes deberían ayudarme aquí.
Podría migrar a twigs para separar el nivel de presentación de la lógica comercial.
Primero, mueva su etiqueta fuera del bucle for de sabelotodo. Por ejemplo:
{* Generate a new select tag? *} <select name="attr_{$obj->mProduct.attributes[k].attribute_name}"> {section name=k loop=$obj->mProduct.attributes} {* Generate a new option tag *} <option value="{$obj->mProduct.attributes[k].attribute_value}"> {$obj->mProduct.attributes[k].attribute_value} </option> {/section} </select>Esto devolverá todos los atributos a un cuadro de selección. Aún necesitará agrupar por nombre de atributo de alguna manera. Esto un poco fuera del alcance de su pregunta, pero:
Método SQL Deberá realizar una consulta SQL GROUP BY DISTINCT en su nombre de atributo para encontrar todos los tipos de atributos relevantes, luego iterar sobre los valores para cada tipo.
Método PHP Continúe consultando de la misma manera que lo hace ahora, pero preprocese sus datos en el backend antes de representarlos en su plantilla inteligente:
$attributes = array() [for each row in sql query] if ($attributes[$row.name] == null) { $attributes[$row.name] = array() } $array_push($attributes[$row.name], $row.value) [/end for]Al final, tendrá un bucle for anidado que hace algo como esto (pseudocódigo):
[For each attribute_name in names] <select name="{attribute_name}"> [For each attribute] <option value="{$obj->mProduct.attributes[k].attribute_value}"> {$obj->mProduct.attributes[k].attribute_value} </option> [/end for (attribute)] </select> [/end for (names)] Si es necesario, puede envolver todo <select/> en una declaración if para ocultarlo si no hay atributos para elegir.