Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OC 3.1.0.0_b Twig ignoring template variables added by view/*/before events #7152

Closed
mhcwebdesign opened this Issue Jan 16, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@mhcwebdesign
Copy link

mhcwebdesign commented Jan 16, 2019

The OpenCart 3.1.0.0-b Twig rendering engine ignores template variables added by view/*/before events when added via lambda functions. E.g. something like this won't work:

<?php
class ControllerExtensionModuleGoogleTagManager extends Controller {

	public $lambda;

	public function callback(&$code) {
		$lambda = $this->lambda;
		$lambda($code);
	}

	// event handler for catalog/view/common/footer/before
	public function ViewCommonFooterBefore( &$route, &$data, &$template=null ) {
		// .....
		// Attach as template filter
		$template->addFilter('extension/module/google_tag_manager/ViewCommonFooterBefore-' . $this->config->get('config_store_id'), $this);
		// .....
		// event handler will run when template calls back this lambda function
		$this->lambda = function (&$code) use (&$route, &$data) {
			$data['new_var'] = 'whatever';
			// .....
			// do some changes to template code
		}
	}
?>

This basically limits the lambda function to changing the template code only, changing the $data array in there has no effect in the final Twig rendering.

This whole concept of using lambda functions is cumbersome, surely there are better approaches!

@mhcwebdesign mhcwebdesign changed the title OC 3.1.0.0.b Twig ignoring template variables added by view/*/before events OC 3.1.0.0_b Twig ignoring template variables added by view/*/before events Jan 18, 2019

@danielkerr

This comment has been minimized.

Copy link
Contributor

danielkerr commented Apr 8, 2019

seems to be the same issue

#7230

@danielkerr danielkerr closed this Apr 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.