Passing config paramater to all presenters

Notice: This thread is very old.
Etruska
Member | 25
+
0
-

Hi,
I would like to pass parameter(s) from configuration to <head> section in layout so it probably has to be passed to all front-end presenters. I guess I could make a service which only purpose would be to carry the parameter and inject the service to BasePresenter. However I don't find such service very useful and also I've read some bad things about using BasePresenter. What would you recommend? Thank you for your advice.

looky
Member | 99
+
0
-

Base presenter is fine, and so is your solution, so I'd say go ahead…

Tomáš Votruba
Moderator | 1114
+
0
-

Hi, you could make a component {control head}.

Ad BasePresenter: I prefer using traits which I pass to presenter. E.g. TWebloaderComponents is more clear than BasePresenter.

Etruska
Member | 25
+
0
-

@**Tomáš Votruba**: I must admit traits are fairly new to me. It does look better then BasePresenter, I'll give it a try :).

Ad component: Component makes sense but I would still have to pass config parameters via service, right? Or am I missing something?

Tomáš Votruba
Moderator | 1114
+
0
-

You can pass it directly to component.

services:
    -
        implement: IHeadComponent
        setup:
            - setParameters(@Nette\DI\Container::parameters)

It's called generated factories, see this article (in czech)

Etruska
Member | 25
+
0
-

I didn't know about this feature, it's really neat :). Thank you.