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

Notice: This thread is very old.

6 years ago

Robin Martinez
Member | 46
+
0
-

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(
	$presenter,
	$httpRequest->getMethod(),
	$params,
	$httpRequest->getPost(),
	$httpRequest->getFiles(),
	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 :)

6 years ago

llsm
Member | 122
+
+1
-

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() {
		parent::beforeRender();
		$this->template->myParam = $this->getParameter('promenna');
	}
}