Page 1 of 1

Please help. Php to Twig in template.

Posted: Sat Dec 02, 2017 3:29 am
by Xciso
Hi. I have been away from OpenCart for about a year, and I seen that many things have been change with the template system. I dont know why they have change to twig, but maybe its better then tpl.

I am now going to update a module to v3.x but I cant get it work.
I have tryed php2twig, but I dont know if it makes my code right.
Code:

Code: Select all

<?php echo $text_stock; ?>
			<?php
$ch = curl_init($mpsu);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$text = curl_exec($ch);
$mpssf = stripos($text, $mpssf);
$mpsss = stripos($text, $mpsss);
$mpsst = stripos($text, $mpsst);
if ($mpsu == false) {
   echo $stock;
}

elseif ($mpssf == true) {
   echo $mpsrf;
}
elseif ($mpsss == true) {
   echo $mpsrs;
}
elseif ($mpsst == true) {
   echo $mpsrt;
}
elseif(!$mpsu && !$mpssf && !$mpsss && !$mpsst) {
   echo $stock;
}
else {
   echo $mpsre;
}
?>
Please help!
Thanks :)

Re: Please help. Php to Twig in template.

Posted: Sat Dec 02, 2017 4:54 am
by straightlight
This code example is incomplete. From which PHP file and location are you trying to code this example from?

Re: Please help. Php to Twig in template.

Posted: Sat Dec 02, 2017 3:39 pm
by Xciso
Hi. Where is it incomplete? It worked with 2.3.0.2.

Can I insert this code in model or controller insted of product.twig?

Re: Please help. Php to Twig in template.

Posted: Sat Dec 02, 2017 4:56 pm
by phinq1910
Try convert smarty to twig

Re: Please help. Php to Twig in template.

Posted: Sat Dec 02, 2017 10:20 pm
by JNeuhoff
Xciso wrote:
Sat Dec 02, 2017 3:39 pm
Hi. Where is it incomplete? It worked with 2.3.0.2.

Can I insert this code in model or controller insted of product.twig?
Most of this code should be in a controller file, not in a template. Looks like a poorly written 3rd party extension to me.

Anyway, if you need a quick solution, our automatic template switcher will let you continue with using *.tpl files in OpenCart 3.x. There is no compelling reason for using Twig.