|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
djsmro Smarty n00b
Joined: 14 Dec 2011 Posts: 4
|
Posted: Wed Jun 06, 2012 4:22 pm Post subject: foreach-Schleife mit Element "XYZ" |
|
|
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 |
|
ovnn Smarty Regular
Joined: 14 Apr 2010 Posts: 82 Location: Germany
|
Posted: Thu Jun 07, 2012 7:17 am Post subject: |
|
|
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 |
|
|
|
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
|