View previous topic :: View next topic |
Author |
Message |
psycco Smarty Rookie
Joined: 08 Aug 2006 Posts: 8
|
Posted: Tue Aug 08, 2006 8:53 am Post subject: tabelle mit foreach und zwei werte in einem durchgang |
|
|
hallo liebe smarty gemeinde,
erstmal muss ich sagen das ich neu bin :>
und dann hab ich hier schon das erste problem mit smarty. was macht man wenn man eine tabelle hat zB 10 werte ausliest aber auf jeder zweile 2 werte nebeneinander haben will?
also förmlich so
<table>
{foreach from=$werte item=user}
<tr>
<td>meine twegen id 1</td>
<td>meine twegen id 2</td>
</tr>
<td>erster wert</td>
<td>hier soll dann der zweite wert stehen</td>
</tr>
{/foreach}
</table>
wie bekomme ich denn sowas gelöst?
viele grüße |
|
Back to top |
|
shannera Administrator
Joined: 13 Feb 2006 Posts: 802 Location: Edertal, Germany
|
Posted: Tue Aug 08, 2006 10:32 am Post subject: |
|
|
Indem man statt {foreach} {section} nimmt, dann sollte das rein theoretisch so gehen:
Code: |
<table>
{section loop=$werte name="counter" step="2"}
<tr>
<td>$werte[counter].id</td>
<td>$werte[counter+1].id</td>
</tr>
<td>$werte[counter].wert</td>
<td>$werte[counter+1].wert</td>
</tr>
{/section}
</table>
|
|
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Tue Aug 08, 2006 11:31 am Post subject: |
|
|
@shannera: Schade nur, dass simple math nicht innerhalb von section indized funktioniert.
@psycco: wenn du eine tabelle so ausgeben willst, riecht das eigentlich danach, dass du gar keine tabelle ausgeben willst sondern floating divs von gleichartigen elementen. |
|
Back to top |
|
psycco Smarty Rookie
Joined: 08 Aug 2006 Posts: 8
|
Posted: Tue Aug 08, 2006 11:43 am Post subject: |
|
|
@messju, jaa das hab ich auch schon probiert aber irgendwie krieg ich das mit der positionierung nicht so einwandfrei hin...ich google einfach mal...danke erstmal für die hilfe |
|
Back to top |
|
gnuffmaster Smarty Elite
Joined: 13 Jul 2006 Posts: 440 Location: Düsseldorf, Germany
|
Posted: Tue Aug 08, 2006 12:35 pm Post subject: |
|
|
So geht das leider alles nicht. Ich habe das ganze mit einer Funktion gelöst. Das ganze ist dann sehr variabel, allerdings auch nicht ganz so trivial bei der Ausgabe hinsichtlich der Formatierung innerhalb einer Tabelle oder so.
split_array:
http://www.phpinsider.com/smarty-forum/viewtopic.php?t=2816
Ich habe es mit Divs gelöst für die tabellarische Darstellung:
Code: |
<tr bgcolor="#EBEBEB">
<td class="text">&</td>
{* get equipment_fields from db, output in "num" columns, and only start to max parts *}
{split_array var=$equipment_options num=2 start=0 max=10 assign="equis"}
{section name=outer loop=$equis}
<td colspan="2" class="text" valign="top">
{section name=inner loop=$equis[outer]}
<div style="padding:3px;"><label><input type="checkbox" name="equipment[]" value="{$equis[outer][inner].id}" />&{$equis[outer][inner].lg}</label></div>
{/section}
</td>
{sectionelse}
<td colspan="4" class="text" valign="top">&</td>
{/section}
</tr>
|
|
|
Back to top |
|
shannera Administrator
Joined: 13 Feb 2006 Posts: 802 Location: Edertal, Germany
|
Posted: Tue Aug 08, 2006 12:36 pm Post subject: |
|
|
@messju: überredet, geht doch nicht...
Aber ich habe da eine Variante, die funktioniert mit zwei Spalten, aber DIVs sind dann doch ein wenig eleganter, da die Lesbarkeit dann doch ein wenig leidet:
Code: |
<table border="1">
{section loop=$werte name="counter" step="1"}
{if $smarty.section.counter.index % 2 == 0}
<tr>
{/if}
<td>{$werte[counter].id}</td>
<td>{$werte[counter].wert}</td>
{if $smarty.section.counter.index % 2 != 0}
</tr>
{/if}
{/section}
</table>
|
|
|
Back to top |
|
psycco Smarty Rookie
Joined: 08 Aug 2006 Posts: 8
|
Posted: Tue Aug 08, 2006 1:46 pm Post subject: |
|
|
ok hier jetzt mal meine gallery lösung, hab es mit divs gelöst und sieht sehr schmuck aus. danke euch allen
Code: | <div id="gallery_spacer"></div>
{foreach from=$gallery item=gallery}
{if $gallery.id_picture is even}
<div id="gallery_item">
<div id="gallery_title">
{if $gallery.title eq ''}
<span class="bold">kein Betreff</span><br />
{else}
<span class="bold">{$gallery.title}</span><br />
{/if}
</div>
<div id="gallery_pictures">
<br />
{if $gallery.picture_path eq '' and $gallery.thumbnail_path eq '' and $gallery.activated eq '0'}
<img src="./images/profile/no_picture.jpg" alt="Kein Foto vorhanden" title="Kein Foto vorhanden" class="border" />
{elseif $gallery.picture_path ne '' and $gallery.thumbnail_path ne '' and $gallery.activated eq '0'}
<img src="./images/profile/picture_not_activated.jpg" alt="Bild wird entwickelt" title="Bild wird entwickelt" class="border" />
{else}
<a href="{$gallery.picture_path}" title="{$gallery.title}"><img src="{$gallery.thumbnail_path}" alt="{$gallery.title}" title="{$gallery.title}" /></a>
{/if}
<br /><br />
</div>
<div id="gallery_commentary">
<p>
{if $gallery.commentary ne ''}
{$gallery.commentary}
{else}
kein Kommentar zum Bild
{/if}
</p>
</div>
<br />
</div>
{else}
<div id="gallery_item">
<div id="gallery_title">
{if $gallery.title eq ''}
<span class="bold">kein Betreff</span><br />
{else}
<span class="bold">{$gallery.title}</span><br />
{/if}
</div>
<div id="gallery_pictures">
<br />
{if $gallery.picture_path eq '' and $gallery.thumbnail_path eq '' and $gallery.activated eq '0'}
<img src="./images/profile/no_picture.jpg" alt="Kein Foto vorhanden" title="Kein Foto vorhanden" class="border" />
{elseif $gallery.picture_path ne '' and $gallery.thumbnail_path ne '' and $gallery.activated eq '0'}
<img src="./images/profile/picture_not_activated.jpg" alt="Bild wird entwickelt" title="Bild wird entwickelt" class="border" />
{else}
<a href="{$gallery.picture_path}" title="{$gallery.title}"><img src="{$gallery.thumbnail_path}" alt="{$gallery.title}" title="{$gallery.title}" /></a>
{/if}
<br /><br />
</div>
<div id="gallery_commentary">
<p>
{if $gallery.commentary ne ''}
{$gallery.commentary}
{else}
kein Kommentar zum Bild
{/if}
</p>
</div>
<br />
</div>
{/if}
{/foreach}
<div id="gallery_spacer"></div> |
|
|
Back to top |
|
Boschs Smarty n00b
Joined: 23 Mar 2011 Posts: 1
|
|
Back to top |
|
|