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

loop=last

 
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
daxx
Smarty Rookie


Joined: 02 Apr 2014
Posts: 14

PostPosted: Sat Apr 12, 2014 5:03 pm    Post subject: loop=last Reply with quote

Hallo...

Ich habe Inhalt in einer DB. Dabei gibt es verschiedene Werte.

Beispiel:

Inhalt1 - Content1 - Option=1
Inhalt2 - Content2 - Option=1
Inhalt3 - Content3 - Option=2
Inhalt4 - Content4 - Option=2
Inhalt5 - Content5 - Option=1
usw..

Die Option= bedeutet die Art der Ausgabe. Nun möchte ich, dass islast und isfirst benutzen aber nur darauf fixiert, was Option=2 hat.

Er soll quasi etwas hinzufügen am Anfang und am Ende bei allem was Option=2 hat und bei Option=1 nichts tun.

Gibts da eine Möglichkeit die in etwa so aussieht ?

$smarty.foreach.ausgabe.option==2.last ?

mfg,
daxx
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun Apr 13, 2014 7:40 am    Post subject: Reply with quote

Da gibt es nichts.

Ich sehe da nur die Möglichkeit das Du Dir in der {foreach} Loop jeweils den letzten Wert von Option in einer Variablen merkst und dann durch entsprechende {if} Abfragen die Übergänge erkennst.
Back to top
View user's profile Send private message
daxx
Smarty Rookie


Joined: 02 Apr 2014
Posts: 14

PostPosted: Sun Apr 13, 2014 9:00 pm    Post subject: Reply with quote

Hallo U.Tews.. Erstmal wieder danke für deine Antwort. Smile

Hast du da einen link oder ein Beispiel, wie sowas aussehen könnte ?

mfg,
daxx
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Mon Apr 14, 2014 1:56 pm    Post subject: Reply with quote

In etwa so:

Code:

{$last = null}
{foreach item=content_ausgabe from=$content}

    {if $content_ausgabe.option1 == 2 && $content_ausgabe.option1 != $last}
        // Hier bei erstem element mit option == 2 (Anfang)
   {/if} 
   {if $last == 2 && $content_ausgabe.option1 != $last}
        // Hier bei erstem element nach option == 2 (Ende)
   {/if}

   // Hier der gemeinsame Loop Code

  {if $content_ausgabe@last && $content_ausgabe.option1 == 2}
    // Hier müsste das Ende nochmal wiederholt werden für den Fall das
       die Loop mit option == 2 endet.
  {\if}

  {$last = $content_ausgabe.option1}

 {/foreach}
Back to top
View user's profile Send private message
daxx
Smarty Rookie


Joined: 02 Apr 2014
Posts: 14

PostPosted: Mon Apr 14, 2014 3:36 pm    Post subject: Reply with quote

Hallo U.Tews... Ansatz hat ganz gut funktioniert...

Ich habe es nun so:

Code:
{assign var="merke" value="0"}
{foreach item=content_ausgabe from=$content name=contentloop}

   {if $content_ausgabe.option2 == 1 && $merke == 0}
   ANFANG OPTION2 MIT WERT 1<br>
   {/if}
   
   {if $merke == 1 && $content_ausgabe.option2 != $merke}
    ENDE OPTION2 MIT WERT 1<br>
   {assign var="merke" value="0"}
   {/if}

    {if $content_ausgabe.option2 == 1}
   AUSGABE OPTION: {$content_ausgabe.head}<br>
   {else}
   AUSGABE NORMAL: {$content_ausgabe.head}<br>
   {/if}
   
   {if $content_ausgabe.option2 == 1}
   {assign var="merke" value="1"}
   {/if}

 {/foreach}


Das klappt auch. Die Ausgabe ist allerdings so:
Quote:
AUSGABE NORMAL: Testinhalt
ANFANG OPTION2 MIT WERT 1
AUSGABE OPTION: Testinhalt
AUSGABE OPTION: Testinhalt
ENDE OPTION2 MIT WERT 1
AUSGABE NORMAL: Testinhalt
ANFANG OPTION2 MIT WERT 1
AUSGABE OPTION: Testinhalt


Der inhalt kann willkürlich sein. Also was die Option angeht. Nun Gibt er es "fast" richtig aus. Nur am Ende fehlt dann wieder das "ENDE OPTION2 MIT WERT1"...

Über einen Lösungsansatz wäre ich dankbar. Smile

mfg,
daxx


Last edited by daxx on Mon Apr 14, 2014 3:50 pm; edited 1 time in total
Back to top
View user's profile Send private message
daxx
Smarty Rookie


Joined: 02 Apr 2014
Posts: 14

PostPosted: Mon Apr 14, 2014 3:44 pm    Post subject: Reply with quote

Wenn ich dein Beispiel nun richtig verstanden habe, ist die Abfrage:

Code:
{if $merke == 1 && $content_ausgabe.option2 != $merke}


ausschließlich auf die Ausgabe von Option2=0 und Option2=1 begrenzt.

Ich möchte das Ergebnis (falls es denn mal irgendwann läuft) erweitern.
Es soll z.B. auch Option2=2 , Option2=3 , Option2=4 usw möglich sein.

Damit soll die Darstellung von Inhalten in verschiedenen Ausgabe-Scripten möglich werden. Im Moment habe ich die normale Ausgabe und ein Ausklapp-Tab/Accordion CSS script.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Mon Apr 14, 2014 3:59 pm    Post subject: Reply with quote

Ach mein lieber....

In Deinem ersten Post hast Du gesagt Du möchtest was spezielles bei einem Options Wert von 2 machen. Darfür war mein Beispiel ausgerichtet.

Ich hatte aus einem alten Beispiel $content_ausgabe.option1 übernommen. Jetzt verwendest Du $content_ausgabe.option2 dass müsste natürlich ersetzt werden.

Soll jetzt was spezielles mit Options Wert 1 gemacht werden, so musst Du einfach alle Vergleiche auf 1 ändern.

Willst Du das ganze für mehrere Options Werte, so musst Du in meinem Beispiel die {if} Blöcke duplizieren und die Vergleichwerte jeweils anpassen.

Mein Beispiel sollte dafür funktionieren.
Back to top
View user's profile Send private message
daxx
Smarty Rookie


Joined: 02 Apr 2014
Posts: 14

PostPosted: Mon Apr 14, 2014 5:43 pm    Post subject: Reply with quote

Bei deinem Beispiel meckerte er über:

if $content_ausgabe@last

Gibt es nicht sagt smarty. Nutze eine alte Version und bin nicht sicher, ob der Admin-Bereich das updaten ohne weiteres zulässt.

Und variablen muss ich mit {assign} setzen. $last nimmt er auch nicht.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Mon Apr 14, 2014 5:57 pm    Post subject: Reply with quote

Ah, sorry du bist auf Smarty2

Code:
{assign var='merke' value = null}
{foreach item=content_ausgabe from=$content name=contentloop}

    {if $content_ausgabe.option2 == 2 && $content_ausgabe.option2 != $merke}
        // Hier bei erstem element mit option == 2 (Anfang)
   {/if} 
   {if $merke == 2 && $content_ausgabe.option2 != $merke}
        // Hier bei erstem element nach option == 2 (Ende)
   {/if}

   // Hier der gemeinsame Loop Code

  {if $smarty.foreach.contentloop.last}
     {if $content_ausgabe.option2 == 2}
    // Hier müsste das Ende nochmal wiederholt werden für den Fall das
       die Loop mit option == 2 endet.
     {/if}
  {\if}

  {assign var='merke' value= $content_ausgabe.option2}

 {/foreach}


Der Optionswertevergleich steht noch auf 2. Aber das kriegst Du hin Very Happy
Back to top
View user's profile Send private message
daxx
Smarty Rookie


Joined: 02 Apr 2014
Posts: 14

PostPosted: Mon Apr 14, 2014 7:29 pm    Post subject: Reply with quote

Ich danke dir erstmal für deine Hilfe! Cool
Werde jetzt mal versuchen das alles hübsch einzubauen. Smile

LG,
daxx
Back to top
View user's profile Send private message
daxx
Smarty Rookie


Joined: 02 Apr 2014
Posts: 14

PostPosted: Mon Apr 14, 2014 8:39 pm    Post subject: Reply with quote

Läuft ! Very Happy
Vielen Dank !

Wink
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