开发者

How can i make record style in following format in smarty template

开发者 https://www.devze.com 2022-12-17 13:56 出处:网络
i want to list the records in following format in smarty template page 1 3 5 ... 2 4 6 ... there should be t开发者_运维技巧he

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 format


Have 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';
}
0

精彩评论

暂无评论...
验证码 换一张
取 消