View previous topic :: View next topic |
Author |
Message |
daxx Smarty Rookie
Joined: 02 Apr 2014 Posts: 14
|
Posted: Sat Apr 12, 2014 5:03 pm Post subject: loop=last |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Apr 13, 2014 7:40 am Post subject: |
|
|
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 |
|
daxx Smarty Rookie
Joined: 02 Apr 2014 Posts: 14
|
Posted: Sun Apr 13, 2014 9:00 pm Post subject: |
|
|
Hallo U.Tews.. Erstmal wieder danke für deine Antwort.
Hast du da einen link oder ein Beispiel, wie sowas aussehen könnte ?
mfg,
daxx |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Apr 14, 2014 1:56 pm Post subject: |
|
|
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 |
|
daxx Smarty Rookie
Joined: 02 Apr 2014 Posts: 14
|
Posted: Mon Apr 14, 2014 3:36 pm Post subject: |
|
|
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.
mfg,
daxx
Last edited by daxx on Mon Apr 14, 2014 3:50 pm; edited 1 time in total |
|
Back to top |
|
daxx Smarty Rookie
Joined: 02 Apr 2014 Posts: 14
|
Posted: Mon Apr 14, 2014 3:44 pm Post subject: |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Apr 14, 2014 3:59 pm Post subject: |
|
|
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 |
|
daxx Smarty Rookie
Joined: 02 Apr 2014 Posts: 14
|
Posted: Mon Apr 14, 2014 5:43 pm Post subject: |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Apr 14, 2014 5:57 pm Post subject: |
|
|
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 |
|
Back to top |
|
daxx Smarty Rookie
Joined: 02 Apr 2014 Posts: 14
|
Posted: Mon Apr 14, 2014 7:29 pm Post subject: |
|
|
Ich danke dir erstmal für deine Hilfe!
Werde jetzt mal versuchen das alles hübsch einzubauen.
LG,
daxx |
|
Back to top |
|
daxx Smarty Rookie
Joined: 02 Apr 2014 Posts: 14
|
Posted: Mon Apr 14, 2014 8:39 pm Post subject: |
|
|
Läuft !
Vielen Dank !
|
|
Back to top |
|
|