Template preprocess
One of the advantages of render arrays is that rendering to HTML happens as late as possible in the final markup generation. Everything is an array until the very last minute.
We then have the opportunity to alter the render array that represents a region before it’s rendered to HTML.
For every theme hook, a preprocess hook exists that can be used to alter the variables sent to the template.
Preprocess hooks can be used to adapt variables to what a frontend needs, so they are usually defined in the theme itself – in our case, in the alps_trips.theme
file.
We need to retrieve site_name
, copyright
, and a set of socials
to be added to the list of variables sent to the region
template:
function alps_trips_preprocess_region(&$variables): void { if ($variables['region'] == 'footer') { $variables['site_name'] = \Drupal::config('system...