Change part of theme according to time of day
You can define new variables in the array $variables in preprocess.

Assuming this is the page template:

modules/mymodule/mymodule.module:

function mymodule_preprocess_page(&amp;$variables) {
  if ( ... ) {
    $variables['daynight'] = 'day';
  }
  else {
    $variables['daynight'] = 'night';
  }
}


Then use the variable in your twig code:

{{ if (daynight == 'day') }}
    &lt;img src="img_during_the_day.jpg"/&gt;
{{ else }}
    &lt;img src="img_during_the_night.jpg"/&gt;
{{ endif }}


Or shorter:

&lt;img src="img_during_the_{{ daynight }}.jpg"/&gt;


You will get some problems with caching. In drupal and in proxies and browsers. So this is probably not a server but a client side solution.