Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Vopros pro smarty {section} | Question about {section}

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: Russian
View previous topic :: View next topic  
Author Message
IceJOKER
Smarty n00b


Joined: 08 Jul 2014
Posts: 2

PostPosted: Tue Jul 08, 2014 2:27 pm    Post subject: Vopros pro smarty {section} | Question about {section} Reply with quote

Есть переменные:
$items //массив с данными(для примера пускай там значения от 0 до 55)

нужно пробежаться по этому массиву и вывести данные в таком виде:

<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
<ul>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
<li>10</li>
</ul>


.......
никак не могу разобраться с {section} smarty

на php сморозил что-то типа этого

<?php

$items = range(0, 27);
$count = count($items);
$pages = ceil($count/5);

for($i = 0, $k=1; $i <= $pages; $i++){
echo '<ul>';
for($j = 1; $j <= 5; $j++, $k++){
if(!isset($items[$k])) break 2;
echo '<li>'.$items[$k].'</li>';
}
echo '</ul>';
}
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon Jul 14, 2014 11:35 pm    Post subject: Reply with quote

Зачем так сложно?

$i = 0;
<ul>
foreach($arr as $v)
{
<li>$v</li>
if(++$i % 5){
</ul><ul>
}
}
</ul>

Надеюсь, в Smarty сам переведёшь?

P.S.
Даже проще.
http://www.smarty.net/docs/en/language.function.foreach.tpl#foreach.property.iteration
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: Russian All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP