|
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 |
bamsi Smarty n00b
Joined: 01 Jul 2017 Posts: 3
|
Posted: Sat Jul 01, 2017 4:19 pm Post subject: X Element aus foreach array anzeigen |
|
|
Hallo,
Wie kann ich aus einer foreach schleife nur ein X beliebiges element anzeigen?
Beispiel wenn ich den vorletzten Element anzeigen möchte?
Der Array:
Code: | Array
(
[0] => stdClass Object
(
[name] => first
)
[1] => stdClass Object
(
[name] => second
)
[2] => stdClass Object
(
[name] => third
)
) |
Mein foreach code:
Code: | {foreach $oItem as $oItems}
{if $oItem@last}
{$oItem->name|count -1}
{/if}
{/foreach} |
|
|
Back to top |
|
elpmis Smarty Elite
Joined: 07 Jun 2007 Posts: 321
|
Posted: Sat Jul 01, 2017 6:21 pm Post subject: |
|
|
Syntaxfehler?
Code: | {foreach $oItems as $oItem} |
|
|
Back to top |
|
bamsi Smarty n00b
Joined: 01 Jul 2017 Posts: 3
|
Posted: Sun Jul 02, 2017 9:07 am Post subject: |
|
|
Ja sorry, aber auch damit funktioniert es nicht
Ausgabe ist dann 0, denke das der count den key zählt und einfach -1 macht. Aber ich möchte "name" anzeigen und nicht den wert |
|
Back to top |
|
bamsi Smarty n00b
Joined: 01 Jul 2017 Posts: 3
|
Posted: Sun Jul 02, 2017 9:49 am Post subject: |
|
|
Hab die Lösung
{assign var=i_kat value=$oItem|@count}
{assign var=i_kat value=$i_kat-2}
{$oItem[$i_kat]->name} |
|
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
|