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

foreach-Schleife mit Element "XYZ"

 
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
djsmro
Smarty n00b


Joined: 14 Dec 2011
Posts: 4

PostPosted: Wed Jun 06, 2012 4:22 pm    Post subject: foreach-Schleife mit Element "XYZ" Reply with quote

Hallo,

ich möchte im .tpl abfragen, ob eine foreach-Schleife ein bestimmtes Element "XYZ" enthält. Wenn ja soll etwas passieren, wenn nein, soll etwas anderes passieren.

Habe nun folgendes:

{foreach item=kategorie from=$event_array.kategorien}
{if $kategorie.name eq "XYZ"}
{include file="_werbung_01.inc.tpl"}
{else}
{include file="_werbung_02.inc.tpl"}
{/if}
{/foreach}

Funktioniert, wenn das array nur ein Element hat. Wenn es aber mehrere Elemente gibt, wird logischerweise für jedes Element eine "Werbung" inkludiert.

Wie könnte ich die Abfrage gestalten, damit in jedem Fall nur eine Werbung inkludiert wird?

Danke!
Back to top
View user's profile Send private message
ovnn
Smarty Regular


Joined: 14 Apr 2010
Posts: 82
Location: Germany

PostPosted: Thu Jun 07, 2012 7:17 am    Post subject: Reply with quote

setze doch vor dem foreach eine neue variable mit dem wert 0 und wenn in der foreach xyz setze die variable auf 1

und dann nach foreach ein include mit der variable im Dateinamen
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