Home php if isset in the TWIG Sampler

if isset in the TWIG Sampler

Author

Date

Category

Hello please tell me, I started using a TWIG template, I just don’t understand how to convert such entry

if (isset ($ _ get ['hash']) & amp; & amp;! empty ($ _ Get ['Hash '])) {
$ hash = $ _get ['hash'];
}

Tell me please. How to work in twig with global variables.


Answer 1, Authority 100%

Access to the global variable can be obtained like this:

$ loader = new twig_loader_filesystem ('templates');
$ twig = new twig_environment ($ Loader);
$ twig- & gt; addglobal ('get', $ _get); // Now GET in the template will correspond $ _Get

Check:

{% if get.hash is defined and get.hash is not empty%}
  {% set hash = get.hash%}
{% endif%}

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions