Programmatic blocks
The demo website has two blocks defined by modules: one that renders a random quote and one that renders the weather forecast of the next hour for the origin location of a trip.
Blocks are defined as plugins and must follow a set of rules to be available on the frontend, but in the end, a block will return a render array exactly as a controller does.
Both blocks are already available in the alps_quote
and alps_weather
modules. The weather forecast one, for example, returns this render array:
$build['content'] = [ '#theme' => 'alps_weather_forecast_single', '#forecast' => $forecast['list'][0], '#city' => $city, '#units' => $this->config ->get('alps_weather.settings')->get('units'), '#cache' => [ 'max-age' => 10800...