Answer the question
In order to leave comments, you need to log in
How to write words to the left of the data?
I'm making a custom module in Drupal8. Now my data that I receive from the API is displayed like this:
18.21
1020
63
Температура: 18
Давление: 1020
Ветер: 63
<?php
namespace Drupal\weather\Controller;
use Drupal\Core\Render\Markup;
class WeatherPage
{
public function getWeather($city)
{
$response = file_get_contents('http://api.openweathermap.org/data/2.5/weather?q='.$city.',&appid=32ae008b1c7259324aa50450687fabf5&units=metric');
$jsn = json_decode($response);
return [
'#markup' => Markup::create(
'<h1>' . $jsn->name . '</h1>' .
'<div>' . $jsn->main->temp . '</div>' .
'<div>' . $jsn->main->pressure. '</div>' .
'<div>' . $jsn->main->humidity. '</div>'
)
];
}
}
$jsn->main->temp
Answer the question
In order to leave comments, you need to log in
(
'<h1>' . $jsn->name . '</h1>' .
'<div>' . 'Температура:' . $jsn->main->temp . '</div>' .
'<div>' . 'Давление:' . $jsn->main->pressure. '</div>' .
'<div>' . 'Ветер:' . $jsn->main->humidity. '</div>'
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question