|
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 |
Conny64 Smarty Rookie
Joined: 10 Mar 2016 Posts: 5
|
Posted: Tue Apr 30, 2019 11:11 am Post subject: Array |
|
|
Hi,
ich bin leider noch ziemlich am Anfang mit Smarty. Hoffe trotzdem auf Hilfe
Ich möchte Werte einem Array zuweisen und komme irgendwie nicht klar.
Ich schreib mal so wie ich es mir vorstelle:
$adresse[name] "Meier"
$adresse[vorname] = "Franz"
$adresse[ort] = "Köln"
$adresse[name] = "Schulz"
$adresse[vorname] = "Susi"
$adresse[ort] = "Hamburg"
{foreach item=id from=$adresse}
{$adresse.name}, {$adresse.vorname} - {$adresse.ort}
{/foreach} |
|
Back to top |
|
Conny64 Smarty Rookie
Joined: 10 Mar 2016 Posts: 5
|
Posted: Tue Apr 30, 2019 11:57 am Post subject: |
|
|
Ich denke ich habe es selbst hinbekommen.
Wäre es denn richtig wenn ich es so machen würde
Code: |
{append var=adress_array value=['name'=>'Meier','vorname'=>'Franz','ort'=>'Köln']}
{append var=adress_array value=['name'=>'Schulz','vorname'=>'Susi','ort'=>'Hamburg']}
{foreach from=$adress_array item=adresse}
{$adresse.name}, {$adresse.vorname} - {$adresse.ort}<br/>
{/foreach}
|
|
|
Back to top |
|
Grizzly Smarty Pro
Joined: 15 Apr 2011 Posts: 172 Location: Germany
|
Posted: Tue Apr 30, 2019 12:46 pm Post subject: |
|
|
Deine Frage hat in erster Linie wenig mit Smarty, sondern viel mehr mit PHP zu tun.
In der Ersten Frage hast du kein wirkliches Array pro "Nutzer" sondern jeder Wert darin wäre ein Element im Array. Also statt 2 Personen hättest du im ersten Fall 6 Personen.
Schau dir auch das hier an: https://www.php.net/manual/de/language.types.array.php
Im Zweiten Fall machst du es zwar grundsätlich besser/richtig. Aber ich würde abraten "logik" in das Template zu integrieren. Der Aufbau deines Arrays sollte im "backend", also sprich in einer PHP-Datei erfolgen |
|
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
|