View previous topic :: View next topic |
Author |
Message |
daxx Smarty Rookie
Joined: 02 Apr 2014 Posts: 14
|
Posted: Wed Apr 02, 2014 7:43 pm Post subject: {if} wird ignoriert ? |
|
|
Hallo... Ich habe ausgaben über ein CMS das mit Smarty arbeitet.
In dem Array steht folgende infos drin: option1 = wert.
Ich habe nun:
Wert = 0 für Normale Ausgabe
Wert = 1 für spezielle Ausgabe
Meine Abfrage mache ich so:
Code: | {foreach item=content_ausgabe from=$content name=contentloop key=K}
{if $content_ausgabe.option1==0}
Ausgabe Normal ( {$content_ausgabe.head} )<br>
{/if}
{if $content_ausgabe.option1==1}
Ausgabe Ausklappbar ( {$content_ausgabe.head} )<br>
{if $smarty.foreach.contentloop.last}
END<br>
{/if}
{/if}
{/foreach} |
Merkwürdigerweise gibt er es nicht richtig aus. Öffne ich nur Werte mit Option1=1 zeigt er es richtig an. Öffne ich Werte mit Option=0, zeigt er aber auch die Daten mit Option=1 an.
Denkfehler in der Abfrage ? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Apr 02, 2014 8:44 pm Post subject: |
|
|
Der Code sieht eigentlich richtig aus.
Setze doch mal $smarty->debugging=true; und schaue was wirklich im Array $content steht. |
|
Back to top |
|
daxx Smarty Rookie
Joined: 02 Apr 2014 Posts: 14
|
Posted: Wed Apr 02, 2014 8:57 pm Post subject: |
|
|
hi...
Danke erstmal für deine Antwort.
Das Array hatte ich schon mal ausgegeben mit :
Code: | <pre>{$content|@print_r}</pre> |
Die Ausgaben sind alle korrekt. Ich habe auch in meiner Ausgabe zur Sicherheit: {$content_ausgabe.option1} eingetragen. Die Werte gibt er richtig aus. Nur in der IF Abfrage wird sie völlig ignoriert.
Ps: smarty->debugging = true; schreibt er mir unable to read debug.tpl in blabla... debug.tpl ist aber vorhanden. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Apr 02, 2014 9:12 pm Post subject: |
|
|
Sieht alles absolut richtig aus.
Welche Smarty Version nutzt Du?
Erfolgen beide Ausgaben wirklich in der gleichen Iteration?
Code: | {foreach item=content_ausgabe from=$content name=contentloop key=K}
{if $content_ausgabe.option1==0}
Ausgabe Normal ( {$content_ausgabe.head} ) {$smarty.foreach.contentloop.iteration}<br>
{/if}
{if $content_ausgabe.option1==1}
Ausgabe Ausklappbar ( {$content_ausgabe.head} ) {$smarty.foreach.contentloop.iteration} <br>
{if $smarty.foreach.contentloop.last}
END<br>
{/if}
{/if}
{/foreach} |
|
|
Back to top |
|
daxx Smarty Rookie
Joined: 02 Apr 2014 Posts: 14
|
Posted: Wed Apr 02, 2014 9:24 pm Post subject: |
|
|
Ganz ehrlich ?
Keinen Schimmer! Bin da kompletter Neuling. Vor 5 Jahren haben ein Freund von mir (Informatiker) und ich ein eigenes CMS angefangen mit dem ich arbeite. Aus Gewohnheit kann ich damit gut umgehen... Leider steht er mir nicht mehr zur Verfügung weil er nun einen Job angenommen hat.
Ich habe
a) Keine Ahnung welches Smarty das ist.
b) Keine Ahnung was du mit Interation meinst.
Die Daten kommen willkürlich.
Beispiel:
id1: Inhalt 1 option1=0
id2: Inhalt 2 option1=0
id3: Inhalt 3 option1=1
id4: Inhalt 4 option1=1
id5: Inhalt 5 option1=0
id6: Inhalt 6 option1=0
usw...
Nun möchte ich alle Daten die option1=1 haben anders ausgeben und NUR diese. Und alle die Option1=0 haben ganz normal und eben auch NUR diese.
Aber aus irgendeinem Grund zeigt er mir die option1=1 Inhalte richtig an aber die Option=0 nicht. Dort wurstet er die Inhalte mit Option1=1 dazwischen.
Merkwürdigerweise so:
Öffne ich ID1-2 zeigt er an:
Inhalt 1 (Option1=0)
Inhalt 2 (Option1=0)
Inhalt 3 (Option1=1)
Inhalt 4 (Option1=1)
Zeige ich die mit Option 1=1 an gibt er es richtig aus. Nur Inhalt 3 und 4.
Bei Inhalt 5 wiederum so:
Inhalt 3 (Option1=1)
Inhalt 4 (Option1=1)
Inhalt 5 (Option1=0)
Ich hoffe das war jetzt nicht zu viel Input |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Apr 02, 2014 9:38 pm Post subject: |
|
|
Ich weiß nicht was Du mit "Öffne ich ID1-2" meinst.
Die Ausgabe
Inhalt 1 (Option1=0)
Inhalt 2 (Option1=0)
Inhalt 3 (Option1=1)
Inhalt 4 (Option1=1)
zeigt doch, dass in diesem Fall das Array $content 4 Einträge hat die in der {foreach} loop abgearbeitet werden.
Das Problem liegt dann nicht in der {if} Abfrage, Sondern dass das Array $content auch Elemente mit Option1 = 1 enthält.
Mit Iteration meinte ich einen Loop Counter den ich zur Kontrolle in meinem Code Beispile eingebaut hatte |
|
Back to top |
|
daxx Smarty Rookie
Joined: 02 Apr 2014 Posts: 14
|
Posted: Wed Apr 02, 2014 10:14 pm Post subject: |
|
|
Es steht sogar mehr drin. Das war nun nur abgekürzt.
Generell sind die Inhalte nochmal gesplittet in Subkategorien. Das handling übernimmt aber alles die Index.php in der alles verarbeitet wird. Wenn ich also die Abfrage
Code: | {if $content_ausgabe.option1==0} und {if $content_ausgabe.option1==1} |
nicht integriere, zeigt er den $content komplett richtig an. Es soll aber eben diese eine Option1 geprüft werden ob sie 0 oder 1 ist und wenn 0 dann XYZ und wenn 1 dann ZYX |
|
Back to top |
|
daxx Smarty Rookie
Joined: 02 Apr 2014 Posts: 14
|
Posted: Wed Apr 02, 2014 10:37 pm Post subject: |
|
|
Habe den Fehler glaube ich gefunden. Es scheint es liegt generell an der Option1... Hat mit dem tpl also gar nichts zutun. Scheinbar ist die Abfrage in der index.php fehlerhaft... Werde das jetzt mal unter die Lupe nehmen...
Super. Bäume im falschen Wald gesucht. |
|
Back to top |
|
|