Jump to content

Is it possible to set API variable in prepend files ?


Zeka
 Share

Recommended Posts

Hi. 

Not sure that it's important but here is my setup:

// site/init.php

wire()->addHookBefore('PageRender::renderPage', function (HookEvent $e) {
	/** @var Page $page */
	/** @var HookEvent $event */
	/** @var Template $template */

	$event = $e->arguments(0);
	$options = $event->arguments(0);
	$page = $event->object;
	$template = $page->template;
	$options['prependFiles'] = [
		"{$template}.routes.php",
		"_init.php",
	];
	$options['appendFiles'] = [
		"layouts/_main.php",
	];
	$event->setArgument(0, $options);
});

 

// site/templates/_init.php

$view = new \stdClass();
$this->wire('v', $view, true);
// site/templates/someteplate.php

bd($v) ---> null

bd(wire('v')); ---> stdClass

So I'm confused why I can't directly access API variable through $v variable in this case but able through wire('v')?

But if I move code from "site/templates/_init.php" to "site/init.php" it is accessible through $v in templates files. 

Is it normal behavior? 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...