How to show categories in header

So if you want to, you could use a controller plugin that encapsulates fetching and caching category data for you. Another possible way could be using a view helper, that fetches and caches category data and displays it in the view. The latter, however, is rather bad style, as it circumvents the principle of doing the business logic (e.g. reading out data) in a controller and not in the view (or a view helper).

Another possible way could be an event listener that provides data for your view you need in every layout. In the following example, something very similar was done.