Is it possible / safe to show a variable from ROUTER in a template?

5 years ago

Robin Martinez
Member | 41

Hello guys!

I am writing myself a custom router. To my surprise, the router itself is working (I have used Nette for about 3 months now), but for a couple of reasons, I need to initialize a variable in my router like this:

 $params['promenna'] = "Ahoj Svete!"

 return new App\Request(
    array(App\Request::SECURED => $httpRequest->isSecured())

and more-or-less, I only need to print it in the main @layout.latte file without passing/processing it through any of presenters.
My question is simple – is there a simple/safe solution to do this? In my example, I pass the variable as a parameter to the dedicated presenter. But maybe there is a different variant.

Thank you for answering me :)

4 years ago

Member | 122

Why do you want to avoid presenter? You can pass it throught basepresenter (all presenters extends basepresenter) to all templates (so it will work in @layout.latte) like this:

abstract class BasePresenter extends Nette\Application\UI\Presenter
    public function beforeRender() {
        $this->template->myParam = $this->getParameter('promenna');