我想用dl list在两个单独的列中拆分大属性表。 Opencart 2.2.0.0版
现在的代码是(在/view/theme/default/template/product/product.tpl中):
<?php if ($attribute_groups) { ?>
<div class="tab-pane tab-content <?php if ($is_active) { echo 'active'; $is_active = false; } ;?>" id="tab-specification">
<dl>
<?php foreach ($attribute_groups as $attribute_group) { ?>
<p><strong><?php echo $attribute_group['name']; ?></strong></p>
<?php foreach ($attribute_group['attribute'] as $attribute) { ?>
<dt><?php echo $attribute['name']; ?></dt>
<dd><?php echo $attribute['text']; ?></dd>
<?php } ?>
<?php } ?>
</dl>
</div>
<?php } ?>
有什么想法吗? 提前谢谢。
答案 0 :(得分:1)
您可以使用foreach将数组拆分为2并循环使用它们。
How can i take an array, divide it by two and create two lists?
<?php if ($attribute_groups) {
$firsthalf = array_slice($attribute_groups, 0, $len / 2);
$secondhalf = array_slice($attribute_groups, $len / 2);
?>
<div class="tab-pane tab-content <?php if ($is_active) { echo 'active'; $is_active = false; } ;?>" id="tab-specification">
<dl>
<?php foreach ($firsthalf as $attribute_group) { ?>
<p><strong><?php echo $attribute_group['name']; ?></strong></p>
<?php foreach ($attribute_group['attribute'] as $attribute) { ?>
<dt><?php echo $attribute['name']; ?></dt>
<dd><?php echo $attribute['text']; ?></dd>
<?php } ?>
<?php } ?>
</dl>
<dl>
<?php foreach ($secondhalf as $attribute_group) { ?>
<p><strong><?php echo $attribute_group['name']; ?></strong></p>
<?php foreach ($attribute_group['attribute'] as $attribute) { ?>
<dt><?php echo $attribute['name']; ?></dt>
<dd><?php echo $attribute['text']; ?></dd>
<?php } ?>
<?php } ?>
</dl>
</div>
<?php } ?>
可能还有css解决方案,但你用php标记它,所以我想这对你来说会更好。