i want to list the records in following format in smarty template page
1 3 5 ...
2 4 6 ...there should be t开发者_运维技巧he ul
li 1
2 in this formatHave smarty loop through the array twice, using the "step" modifier to skip every-other entry:
<ul>
{section name=index loop=$myList start=0 step=2}<li>{$myList[index]}</li>{/section}
</ul>
<ul>
{section name=index loop=$myList start=1 step=2}<li>{$myList[index]}</li>{/section}
</ul>
Combine that with the CSS display:block; width:50px;
or display:inline-block
(though not all browsers support "inline-block") and you should get the appearance you'd like.
AFAIR neither HTML/CSS nor Smarty doesn't provide any function to deal with that kind of layout, so I'm afraid you'll have to create n/2 lists and each list will have to be displayed as inline-block element (CSS: display: inline-block;
).
$myList = array(1, 2, 3, 4, 5, 6);
$listsCount = ceil(count($myList) / 2);
for ($i = 0; $i < $listsCount; ++$i) {
echo 'UL';
for ($j = $i * 2; $j < $i * 2 + 2; ++$j) {
echo 'LI ' . $myList[$j] . '/LI';
}
echo '/UL';
}
精彩评论