tags:

views:

43

answers:

2

hi

i want to list the records in following format in smarty template page

1 3 5 ...
2 4 6 ...

there should be the ul

li 1
2 in this format

A: 

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';
}
Crozin
Not sure your code does what you think it does... Your code generates three ULs, and if using inline-block to stack the LI's horizontally, you'd get "1 2" on the first line, "3 4" on the next, and "5 6" on the third, making a vertical list, rather than a horizontal one.
MidnightLightning
+1  A: 

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.

MidnightLightning
ok thanx for your answer it is very usefull.
Rajendra Banker