I'm building a site that requires having user data (eg, user name) passed to every view. So I basically want the Fuel equivalent of a Laravel View Composer.
However, I can't seem to find one in Fuel. Am I missing it, or does this not exist? I'd rather not set the user data manually for each view in the controller, since that could become very onerous to maintain.
I looked at Presenters, but having to create a separate presenter for each view (or do a manual override each time) seemed like the poorer alternative.
Stupid question- where would I set these globals? Because from the documentation it looks like you set it from within a controller method if you're using view partials and want data to be available to each one.
In my case I just want to call this data one time and when a View is rendered it automatically knows to "do this too" (DRY)
Otherwise it seems like I have to call this data and pass it to the template by hand each time I render a View?
They are global, so you only have to do it once. Where greatly depends on your application architecture.
Some use the before() method of a base controller, some have an "application init" class that is always loaded in the config, some use config files directly, etc.