What is the replacement pattern in rewrite ouput for current user id?
The twig variables in {{ }} are replacement patterns for fields. Globally available tokens are accessed by their usual square brackets syntax:

[current-user:uid]


Custom text field

This token works in a global text area, but not a custom text field, because this plugin Drupal\views\Plugin\views\field\Custom doesn't have global token replacement. You need to extend it and override renderAltered():

/src/Plugin/views/field/CustomToken.php

&lt;?php

namespace Drupal\mymodule\Plugin\views\field;

use Drupal\views\Plugin\views\field\Custom;

/**
 * A handler to provide a field extending custom by global token replacement.
 *
 * @ingroup views_field_handlers
 *
 * @ViewsField("custom")
 */
class CustomToken extends Custom {

  /**
   * {@inheritdoc}
   */
protected function renderAltered($alter, $tokens) {
    return $this-&gt;viewsTokenReplace($this-&gt;globalTokenReplace($alter['text']), $tokens);
  }
}


and tell the plugin manager about the new class:

mymodule.module:

function mymodule_views_plugins_field_alter(array &amp;$plugins) {
  $plugins['custom']['class'] = 'Drupal\mymodule\Plugin\views\field\CustomToken';
}


This applies the function globalTokenReplace() before the twig patterns are replaced.

Then you can use

{% if anotherfield_id == '[current-user:uid]' %} YES {% else %} NO {% endif %}


You have to enclose the token in single quotes so that you get a valid twig syntax after the global tokens are replaced.

Global text area

A global text area in header/footer is exactly the opposite, it supports global tokens but not Twig.

You could do the same as before and add Twig support in a custom plugin. But there is an easier solution. Install the module Twig input filter and go to "Text formats and editors" in Configuration and enable the Twig filter for the text format you use in the text area.