I have a PHP code and try to convert to twig with many convertors, but every time code is not working.
Original code:
<?php
$homepage = "/";
$currentpage = $_SERVER['REQUEST_URI'];
echo $_SERVER['REQUEST_URI'];
if ($homepage == $currentpage) { ?>
some html here
<?php }
else { ?>
other html here
<?php } ?>
Converted code:
{% set homepage "/" %}
{% set currentpage _SERVER.REQUEST_URI %}
{{ _SERVER.REQUEST_URI }}
{% if homepage == currentpage %}
some html here
{% else %}
other html here
{% endif %}
I try to change the code many times, every time errors happened. The result:
Fatal error: Uncaught TwigErrorSyntaxError: Unexpected token “string” of value “/” (“end of statement block” expected)
New contributor
Eduard Dimitroff is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.