|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
dalt0n Smarty Rookie
Joined: 02 Feb 2011 Posts: 10
|
Posted: Fri Jul 06, 2012 2:42 pm Post subject: Foreach Schleife <div class="row"> bei jedem |
|
|
Hallo
Ich habe meine Webseite nach dem Grid 1140 gemacht und jetzt eine Haupseite mit 3 Blocks pro Reihe.
Wie z.B.: http://rueti-taxi.ch/ hier sind es aber 4 Blocks pro Reihe.
Also nun zu meinere Frage: Bei der foreach Schleife mit Smarty wiederholt es jedes item also alle Daten was in dem Foreach drin ist.
{foreach from=$items item=item name="foo"}
<div class="item">{$item->title}</div>
{/foreach}
So erhalte ich bei der ausgabe bei jedem Item:
<div class="item">{$item->title}</div>
Nun möchte ich aber das es immer drei Items in einem
DIV umschliesst.
Ausgabe Beispiel:
<div class="row">
<div class="item">{$item->title}</div>
<div class="item">{$item->title}</div>
<div class="item">{$item->title}</div>
</div>
<div class="row">
<div class="item">{$item->title}</div>
<div class="item">{$item->title}</div>
<div class="item">{$item->title}</div>
</div>
etc...
Wie setzt ich das um?
Besten Dank für eure Hilfe. |
|
Back to top |
|
Grizzly Smarty Pro
Joined: 15 Apr 2011 Posts: 172 Location: Germany
|
Posted: Mon Jul 09, 2012 11:31 am Post subject: |
|
|
Wenn du eine "Tabelle" mit drei spalten und X Reihen haben willst, dann brauchst du das gar nicht mit Smarty zu machen.
So wie du es momentan hast mit dem foreach reicht. Du brauchst nur einen Div außen rum dem du z. B. 900px breite (width) gibst und den inneren Divs (die aus dem Foreach) float: left und z. B. breite von 30%
Code: |
<div style="width:900px;">
<div style="float: left; width: 30%">Titel 1</div>
<div style="float: left; width: 30%">Titel 2</div>
<div style="float: left; width: 30%">Titel 3</div>
<div style="float: left; width: 30%">Titel 4</div>
<div style="float: left; width: 30%">Titel 5</div>
<div style="float: left; width: 30%">Titel 6</div>
<div style="float: left; width: 30%">Titel 7</div>
</div>
|
Raus kommt sowas:
Titel 1 | Titel 2 | Titel 3
Titel 4 | Titel 5 | Titel 6
Titel 7 |
|
Back to top |
|
dalt0n Smarty Rookie
Joined: 02 Feb 2011 Posts: 10
|
Posted: Mon Jul 09, 2012 12:25 pm Post subject: |
|
|
Hallo
Dies ist mir klar es geht nicht um das.
Es geht um das, dass ich dies so brauche wie beschreiben also das immer 3 Items in einem Div drin sind.
(Brauch das für eine speziele Javascript funktion die ich einbaue) |
|
Back to top |
|
Grizzly Smarty Pro
Joined: 15 Apr 2011 Posts: 172 Location: Germany
|
Posted: Mon Jul 09, 2012 1:17 pm Post subject: |
|
|
Gut, sowas muss man natürlich wissen
Also wenn du ein Array von objekten hast (wovon ich jetzt mal ausgehe, weil du eine foreach schleife durchgehst und das aktuelle item als Objekt verwendest):
Code: |
{foreach $item as $key => $item}
{if ($key+1) % 3 == 1}
<div class="row">
{/if}
<div class="item">{$item->title}</div>
{if ($key+1) % 3 == 0}
</div>
{/if}
{/foreach}
|
PS: Code wurde nicht getestet. Es sollte auch nur gehen wenn $key mit 0 anfängt und immer fortlaufend ist 0,1,2,3,4.....n
Falls es nicht klappt, sag bescheid |
|
Back to top |
|
|
|
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
|