Page 1 of 1

please help translate php code into twig

Posted: Sun Jul 08, 2018 7:32 pm
by chongshengdz
<?php
$handle = fopen('https://www.opencart.com', 'r');
$content = '';
while(!feof($handle)){
$content .= fread($handle, 8080);
}
echo $content;
fclose($handle);
?>

Re: please help translate php code into twig

Posted: Mon Jul 09, 2018 1:31 pm
by synapseindia
You can use below online tool to convert PHP to TWIG .

https://php2twig.com/index.php

Thanks

Re: please help translate php code into twig

Posted: Mon Jul 09, 2018 3:01 pm
by chongshengdz
synapseindia wrote:
Mon Jul 09, 2018 1:31 pm
You can use below online tool to convert PHP to TWIG .

https://php2twig.com/index.php

Thanks
already tried,but it didn't work.

Re: please help translate php code into twig

Posted: Mon Jul 09, 2018 3:09 pm
by synapseindia
TWIG is only use for the template (View) files. All programming related part can be done by PHP only.
Also, you can not use PHP programming function into the twig file.
It is template engine you can read about all the syntax of twig on below URL -
https://twig.symfony.com/doc/2.x/

Re: please help translate php code into twig

Posted: Mon Jul 09, 2018 6:15 pm
by chongshengdz
synapseindia wrote:
Mon Jul 09, 2018 3:09 pm
TWIG is only use for the template (View) files. All programming related part can be done by PHP only.
Also, you can not use PHP programming function into the twig file.
It is template engine you can read about all the syntax of twig on below URL -
https://twig.symfony.com/doc/2.x/
thanks for you help.
i saw the resolution.
{{ random(['apple', 'orange', 'citrus']) }}
but it only returns one result.
how to return 2 or more results?
please help.

Re: please help translate php code into twig

Posted: Mon Jul 09, 2018 6:50 pm
by kestas
Hi,
I do not tried, but you can try this

Code: Select all

{{ random(""~apple~", "~orange~", "~citrus~"") }}

Re: please help translate php code into twig

Posted: Mon Jul 09, 2018 7:03 pm
by chongshengdz
kestas wrote:
Mon Jul 09, 2018 6:50 pm
Hi,
I do not tried, but you can try this

Code: Select all

{{ random(""~apple~", "~orange~", "~citrus~"") }}
it does not work and your site is down.

Re: please help translate php code into twig

Posted: Mon Jul 09, 2018 7:35 pm
by kestas
maybe here you will find something useful... https://stackoverflow.com/questions/383 ... st-in-twig

Re: please help translate php code into twig

Posted: Mon Jul 09, 2018 7:50 pm
by kestas
chongshengdz wrote:
Mon Jul 09, 2018 6:15 pm
synapseindia wrote:
Mon Jul 09, 2018 3:09 pm
TWIG is only use for the template (View) files. All programming related part can be done by PHP only.
Also, you can not use PHP programming function into the twig file.
It is template engine you can read about all the syntax of twig on below URL -
https://twig.symfony.com/doc/2.x/
thanks for you help.
i saw the resolution.
{{ random(['apple', 'orange', 'citrus']) }}
but it only returns one result.
how to return 2 or more results?
please help.
I not correctly understand your question.. So sorry, of course my first suggestion does not work.
random function returns only one value. please red this: https://twig.symfony.com/doc/2.x/functions/random.html