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

[Suggestion] Add support for new TWIG version #159

Closed
condor2 opened this issue Jul 24, 2020 · 4 comments
Closed

[Suggestion] Add support for new TWIG version #159

condor2 opened this issue Jul 24, 2020 · 4 comments

Comments

@condor2
Copy link

condor2 commented Jul 24, 2020

Because in versions 3.0.3.5, 3.0.3.6 and 3.1.0.0b TWIG was updated and moved to storage, VQMOD will not work.

@condor2 condor2 changed the title [ Sugestion] Add support for new TWIG version [Sugestion] Add support for new TWIG version Jul 24, 2020
@atnaples
Copy link

atnaples commented Aug 8, 2020

Did you find a solution?

Nothing wrong with vqMod or ocMod

I believe it's another step to block any changes/modifications of the greatest OpenCart code.

The problem with /system/library/template/twig.php file
modification.xml does not work and DOES NOT help
The system renders template only from original directories ONLY, I hope I am right

Try to replace the content of this file with the code below, I's helped me

<?php
namespace Template;
final class Twig {
	private $data = array();

	public function set($key, $value) {
		$this->data[$key] = $value;
	}
	
	public function render($template, $cache = false) {
				
		$loader = new \Twig\Loader\FilesystemLoader();
		
		// specify where to look for templates
		if (defined('DIR_CATALOG') && is_dir(DIR_MODIFICATION . 'admin/view/template/')) {	
			$loader->addPath(DIR_MODIFICATION . 'admin/view/template/');
		} elseif (is_dir(DIR_MODIFICATION . 'catalog/view/theme/')) {
			$loader->addPath(DIR_MODIFICATION . 'catalog/view/theme/');
		}
		
		$loader->addPath(DIR_TEMPLATE);

		// initialize Twig environment
		$config = array(
			'autoescape'  => false,
			'debug'       => false,
			'auto_reload' => true,
			'cache' 			=> false
		);

		if ($cache) {
			$config['cache'] = DIR_CACHE . 'template/';
		}
		
		// echo ($cache? 'true': 'false'), ' --- '; print_r($config);
		$this->twig = new \Twig\Environment($loader, $config);
		
		try {
			// load template
			$template = $this->twig->loadTemplate($template . '.twig');
			
			return $template->render($this->data);
		} catch (Exception $e) {
			trigger_error('Error: Could not load template ' . $template . '!');
			exit();	
		}	
	}	
}

@condor2
Copy link
Author

condor2 commented Aug 8, 2020

I don't use VQMOD. It was just a suggestion for developer to add compatibility.

@condor2 condor2 changed the title [Sugestion] Add support for new TWIG version [Suggestion] Add support for new TWIG version Aug 8, 2020
@tmtung144
Copy link

up

@MarvinKlein1508
Copy link

Too add compatibility you can install this extension.
https://www.opencart.com/index.php?route=marketplace/extension/info&extension_id=39911

Alternativly add this code in vqmod_opencart.xml

<file path="system/library/template/twig.php" error="skip" info="fix Core Opencart twig files modification">
	<operation>
		<search><![CDATA[$file = DIR_TEMPLATE . $filename . '.twig';]]></search>
		<add position="replace"><![CDATA[$file = modification( DIR_TEMPLATE . $filename . '.twig' );
		if( class_exists('VQMod') ) {
			$file = \VQMod::modCheck($file);
		}
		]]></add>
	</operation>
</file>

A implemented fix for this would be nice.

@condor2 condor2 closed this as completed Jan 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants