|
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 |
omexlu Smarty Rookie
Joined: 13 Mar 2014 Posts: 27
|
Posted: Sun May 29, 2016 11:51 am Post subject: Foreach in php und in tpl ausgeben |
|
|
Hallo,
Ich arbeite gerade an einer API die das Wetter ausliesst und diese wird normal so abgerufen (in php):
Code: | foreach($conditions_today as $cond) {
$echo $cond->getTime('H') . ': ' . $cond->getTemperature(). $cond->getHumidity()*100 . $cond->getSummary() . "<br>";
} |
Wie kann ich das jetzt in PHP auslesen und im Template ausgeben?
Ich hatte es probiert
Code: | foreach($conditions_today as $cond) {
$row = $cond->getTime('H') . ': ' . $cond->getTemperature(). $cond->getHumidity()*100 . $cond->getSummary() . "<br>";
}
$smarty->assign('row, $row); |
Im tpl:
Das funktioniert auch jedoch leider wird nur eine Zeile ausgegeben. Wie mache ich das am besten?
Danke im voraus |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sun May 29, 2016 4:59 pm Post subject: |
|
|
PHP: Code: | $_cond = array();
foreach($conditions_today as $cond) {
$_cond[] = array(
'time' => $cond->getTime(),
'temperature' => $cond->getTemperature(),
'humidity' => $cond->getHumidity(),
'text' => $cond->getSummary()
);
}
$smarty->assign('conditions', $_cond); |
Smarty: Code: | {foreach $conditions as $condition}
<tr><td>{$condition.time|date_format:"H"}</td>
<td>{$condition.temperature} °C</td>
<td>{$condition.humidity * 100}%</td>
<td>{$condition.text|escape}</td></tr>
{foreachelse}
<tr><td colspan="4">Seriously, what kind of weather do you expect after the end of times?</td></tr>
{/foreach} |
(In short, you're doing it wrong.) |
|
Back to top |
|
omexlu Smarty Rookie
Joined: 13 Mar 2014 Posts: 27
|
Posted: Mon May 30, 2016 7:50 am Post subject: |
|
|
Works thanks |
|
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
|