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

tabelle mit foreach und zwei werte in einem durchgang

 
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: German
View previous topic :: View next topic  
Author Message
psycco
Smarty Rookie


Joined: 08 Aug 2006
Posts: 8

PostPosted: Tue Aug 08, 2006 8:53 am    Post subject: tabelle mit foreach und zwei werte in einem durchgang Reply with quote

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
View user's profile Send private message
shannera
Administrator


Joined: 13 Feb 2006
Posts: 802
Location: Edertal, Germany

PostPosted: Tue Aug 08, 2006 10:32 am    Post subject: Reply with quote

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
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Tue Aug 08, 2006 11:31 am    Post subject: Reply with quote

@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
View user's profile Send private message Send e-mail Visit poster's website
psycco
Smarty Rookie


Joined: 08 Aug 2006
Posts: 8

PostPosted: Tue Aug 08, 2006 11:43 am    Post subject: Reply with quote

@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 Smile
Back to top
View user's profile Send private message
gnuffmaster
Smarty Elite


Joined: 13 Jul 2006
Posts: 440
Location: Düsseldorf, Germany

PostPosted: Tue Aug 08, 2006 12:35 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
shannera
Administrator


Joined: 13 Feb 2006
Posts: 802
Location: Edertal, Germany

PostPosted: Tue Aug 08, 2006 12:36 pm    Post subject: Reply with quote

@messju: überredet, geht doch nicht... Wink

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
View user's profile Send private message
psycco
Smarty Rookie


Joined: 08 Aug 2006
Posts: 8

PostPosted: Tue Aug 08, 2006 1:46 pm    Post subject: Reply with quote

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
View user's profile Send private message
Boschs
Smarty n00b


Joined: 23 Mar 2011
Posts: 1

PostPosted: Wed Mar 23, 2011 12:14 pm    Post subject: Reply with quote

Hallo! Ich mag divs nicht besonders, was wäre denn eine denkbare Alternative? Danke schonmal
Duplikate löschen

Gruß Manuel


_________________
http://www.finanznachrichten.de/nachrichten-2011-02/19236692-apple-verschaerft-kontrolle-ueber-itunes-plattform-016.htm
http://www.zertifikateboard.de/
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: German 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