Data from database in a layout file

How do I use database data in a layout file? From the controller, I will be calling a view file and passing in page specific data, but in my layout, I would like to pull settings data for things like site title that I don’t want to hard code, and I don’t want to pass from my controller every time I load a view.

Hey @SouthRibbleTech! :wave:

You cannot and you shouldn’t do any database stuff in your view. They should be “dumb” and only display the given data.

What I recommend you is to create a provider/hook that read your database and add them as global values.

If your data depends on the current request, you can also use middlware with runtime values.

Thanks for that. Absolutely agree about database queries in the view. I just didn’t know where to pull data from the database that could be included in every view. I will take a look at providers and hooks as an option.