Get User IP Address in Twig Template Is there a way to get the user's IP address in a twig template? All the twig examples I find say to do it like this:

{% set ipAddr = app.request.server.get("REMOTE_ADDR") %}


But this variable always returns NULL. These examples aren't specific to Drupal so I'm guessing part of the Drupal implementation blocks/omits this.
Suppose you want to get the ip in the page.html.twig file.

in your 


  YOURTHEME.theme


you can try

use Symfony\Component\HttpFoundation;

function YOURTHEME_preprocess_page(&amp;$variables) {
  $variables['page']['ip'] = \Drupal::request()-&gt;getClientIp();

}


in your template 


  page.html.twig


you can try:

{{ page.ip }}