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

{if} wird ignoriert ?

 
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: Wed Apr 02, 2014 7:43 pm    Post subject: {if} wird ignoriert ? Reply with quote

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


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

PostPosted: Wed Apr 02, 2014 8:44 pm    Post subject: Reply with quote

Der Code sieht eigentlich richtig aus.

Setze doch mal $smarty->debugging=true; und schaue was wirklich im Array $content steht.
Back to top
View user's profile Send private message
daxx
Smarty Rookie


Joined: 02 Apr 2014
Posts: 14

PostPosted: Wed Apr 02, 2014 8:57 pm    Post subject: Reply with quote

hi... Smile

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. Confused

Ps: smarty->debugging = true; schreibt er mir unable to read debug.tpl in blabla... debug.tpl ist aber vorhanden.
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Wed Apr 02, 2014 9:12 pm    Post subject: Reply with quote

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


Joined: 02 Apr 2014
Posts: 14

PostPosted: Wed Apr 02, 2014 9:24 pm    Post subject: Reply with quote

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. Smile

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 Smile
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Wed Apr 02, 2014 9:38 pm    Post subject: Reply with quote

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


Joined: 02 Apr 2014
Posts: 14

PostPosted: Wed Apr 02, 2014 10:14 pm    Post subject: Reply with quote

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


Joined: 02 Apr 2014
Posts: 14

PostPosted: Wed Apr 02, 2014 10:37 pm    Post subject: Reply with quote

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. Embarassed
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