Show a list of pages but hide the current page from the list My setup

I'd like to show a navigation menu listing all my page entries.
In my layout file, I include a template for the navigation:

_layout.twig:

    &lt;main&gt;
      &lt;section id="nav"&gt;
        {% include "_includes/navigation.twig" %}
      &lt;/section&gt;

      &lt;section id="content"&gt;
        {% block content %}
        {% endblock %}
      &lt;/section&gt;
    &lt;/main&gt;


The current page is shown in the content block.

My question

Is there a way to globally access the currently viewed page, from inside the navigation.twig template. That way I could do:

{% set currentPageId = SOME_COOL_GLOBAL_FUNCTION %}
{% set pages = craft.entries.section('pages').id('not ' ~ currentPageId).all() %}
&lt;nav id="navigation"&gt;
    &lt;ul&gt;
        {% for page in pages %}
            &lt;li&gt;{{ page.getLink() }}&lt;/li&gt;
        {% endfor %}
    &lt;/ul&gt;
&lt;/nav&gt;
To me it looks like the entries in the section with the handle pages have their own URLs. This means that if you visit a URL that belongs to an entry in that section Craft will automatically make that entry available in the template as the entry variable. That being said your solution is in this case:

{% set currentPageId = entry.id %}
{% set pages = craft.entries.section('pages').id('not ' ~ currentPageId).all() %}
&lt;nav id="navigation"&gt;
    &lt;ul&gt;
        {% for page in pages %}
            &lt;li&gt;{{ page.getLink() }}&lt;/li&gt;
        {% endfor %}
    &lt;/ul&gt;
&lt;/nav&gt;


Or as an alternative:

{% set pages = craft.entries.section('pages').all() %}
&lt;nav id="navigation"&gt;
    &lt;ul&gt;
        {% for page in pages if page.id != entry.id %}
            &lt;li&gt;{{ page.getLink() }}&lt;/li&gt;
        {% endfor %}
    &lt;/ul&gt;
&lt;/nav&gt;


Here is a read about how Twig handles variable scope if you ask yourself why the entry variable is available in the included template:
https://nystudio107.com/blog/twig-processing-order-and-scope

Also, here is a link to Twig's docs on conditional for loops: https://twig.symfony.com/doc/2.x/tags/for.html#adding-a-condition