" Smarty的"将div拆分成多列?

时间:2013-11-25 20:45:30

标签: php html smarty

我需要一些关于聪明的帮助。我想分开我的结果,但我无法做到。 当我运行我的代码时,它就像;

游戏1
游戏2
游戏3
游戏4
游戏5
游戏6

但我希望它看起来像这样,

游戏1游戏4
游戏2游戏5
游戏3游戏6

游戏1游戏2
游戏3游戏4
游戏5游戏6

任何提示?

提前致谢

    {foreach from=$newgames item=games}
<div style="height:120px; width:420px;">
<div class="gamepic">
                        <a href="{$siteadres}/{$games.seobaslik}.html" alt="{$games.baslik}" title="{$games.baslik}">
                            <img style="border:none; " src="{$games.resim}" alt="{$games.baslik}" data-original="{$games.resim}" height="100" width="100"/>
                        </a>
</div>
<div class="gamedesc">
<span class="gametitle">{$games.baslik}</span>
<div class="itemcontent">{$games.aciklama}</div>
<div style="float:left; padding-bottom:-15px;">Played: {$games.ptime}</div><div style="float:right;"> <a href="{$siteadres}/{$games.seobaslik}.html" title="{$games.baslik}"><img style="border:none;" src="{$siteadres}/temalar/{$tema}/images/play.png"/></a></div>

</div>
</div>

            {/foreach}

1 个答案:

答案 0 :(得分:0)

如果你使用Smarty3,你必须使用@index property,创建一个包含列数的模块,然后插入关闭/打开div。

{* output empty row on the 4th iteration (when index is 3) *}
<table>
{foreach $items as $i}
  {if $i@index eq 3}
     {* put empty table row *}
     <tr><td>nbsp;</td></tr>
  {/if}
  <tr><td>{$i.label}</td></tr>
{/foreach}
</table>

或者使用smarty 2,您必须使用iteration property文档。 :

<table>
{section name=co loop=$contacts}
  {if $smarty.section.co.iteration % 5 == 1}
    <tr><th>&nbsp;</th><th>Name></th><th>Home</th><th>Cell</th><th>Email</th></tr>
  {/if}
  <tr>
    <td><a href="view.php?id={$contacts[co].id}">view<a></td>
    <td>{$contacts[co].name}</td>
    <td>{$contacts[co].home}</td>
    <td>{$contacts[co].cell}</td>
    <td>{$contacts[co].email}</td>
  <tr>
{/section}
</table>

正如Matthew Blancarte所说,你可以使用CSS3 like this或使用此other method

相关问题