Answers.Body: <p>To me it looks like the entries in the section with the handle <code>pages</code> 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 <code>entry</code> variable. That being said your solution is in this case:</p>
  
  <pre><code>{% 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;
  </code></pre>
  
  <p>Or as an alternative:</p>
  
  <pre><code>{% 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;
  </code></pre>
  
  <p>Here is a read about how Twig handles variable scope if you ask yourself why the <code>entry</code> variable is available in the included template:
  <a href="https://nystudio107.com/blog/twig-processing-order-and-scope" rel="nofollow noreferrer">https://nystudio107.com/blog/twig-processing-order-and-scope</a></p>
  
  <p>Also, here is a link to Twig's docs on conditional for loops: <a href="https://twig.symfony.com/doc/2.x/tags/for.html#adding-a-condition" rel="nofollow noreferrer">https://twig.symfony.com/doc/2.x/tags/for.html#adding-a-condition</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-08T17:48:22.347Z
Answers.Text: Thanks so much for the answer, and the explanation link too!
Answers.UserDisplayName: gkpo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-07T13:36:04.060Z
Answers.LastActivityDate: 2020-06-07T13:36:04.060Z
Answers.UserDisplayName: Johannes
Body: <h3>My setup</h3>
  
  <p>I'd like to show a navigation menu listing all my page entries.
  In my layout file, I include a template for the navigation:</p>
  
  <p>_layout.twig:</p>
  
  <pre><code>    &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;
  </code></pre>
  
  <p>The current page is shown in the content block.</p>
  
  <h3>My question</h3>
  
  <p>Is there a way to globally access the currently viewed page, from inside the navigation.twig template. That way I could do:</p>
  
  <pre><code>{% 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;
  </code></pre>
  
Tags: <craft3><globals><request>
Title: Show a list of pages but hide the current page from the list
ThreadText: # Show a list of pages but hide the current page from the list
  
  (Asked by: username_0 on 2020-06-06)
  
  ### 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:
  
  ```
      <main>
        <section id="nav">
          {% include "_includes/navigation.twig" %}
        </section>
  
        <section id="content">
          {% block content %}
          {% endblock %}
        </section>
      </main>
  
  ```
  
  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() %}
  <nav id="navigation">
      <ul>
          {% for page in pages %}
              <li>{{ page.getLink() }}</li>
          {% endfor %}
      </ul>
  </nav>
  
  ```
  
  **Tags:** craft3, globals, request
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-06-07. Score: 2 | Accepted answer
  
  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() %}
  <nav id="navigation">
      <ul>
          {% for page in pages %}
              <li>{{ page.getLink() }}</li>
          {% endfor %}
      </ul>
  </nav>
  
  ```
  
  Or as an alternative:
  
  ```
  {% set pages = craft.entries.section('pages').all() %}
  <nav id="navigation">
      <ul>
          {% for page in pages if page.id != entry.id %}
              <li>{{ page.getLink() }}</li>
          {% endfor %}
      </ul>
  </nav>
  
  ```
  
  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>
  
  > **Comments:**
  > **username_0**: Thanks so much for the answer, and the explanation link too!  
  
  ---
  
  