Answers.Body: <p>This is exactly what caching is supposed to do... flatten the Twig code down to basic HTML, and serve that up instead of dynamically rendering it. Using <code>globally</code> means that the HTML would be identical on every page, which is not really what you want here.</p>
  
  <p>Get rid of <code>globally</code>, so it can cache separately for each page. Since the URL is supposed to affect how that snippet is rendered, you don't want to cache <code>globally</code>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-16T22:07:00.393Z
Answers.LastActivityDate: 2015-11-16T22:07:00.393Z
Answers.UserDisplayName: Lindsey D
Body: <p>I have a long entry list of authors and I am using global cache to help with the page load, but this global cache prevents the <code>if</code> statement from adding <code>selected</code> to the appropriate option. When I remove the global cache everything performs as intended.</p>
  
  <pre><code>&lt;select name="filter-by-author" onchange="window.location.href=this.value;"&gt;
      &lt;option value="/blog"&gt;All Authors&lt;/option&gt;
          {% cache globally %}
              {% nav author in craft.users({ group: 'blogAuthors', order: 'firstName', limit: null }) %}
                  &lt;option value="{{ url('blog/author/'~author.username) }}"
                  {% if craft.request.getLastSegment() == author.username %}selected{% endif %}&gt;
                  {{ author.name | title }}
                  &lt;/option&gt;
              {% endnav %}
          {% endcache %}
  &lt;/select&gt;
  </code></pre>
  
Tags: <cache>
Title: Global Cache Working too well?
ThreadText: # Global Cache Working too well?
  
  (Asked by: username_0 on 2015-11-16)
  
  I have a long entry list of authors and I am using global cache to help with the page load, but this global cache prevents the `if` statement from adding `selected` to the appropriate option. When I remove the global cache everything performs as intended.
  
  ```
  <select name="filter-by-author" onchange="window.location.href=this.value;">
      <option value="/blog">All Authors</option>
          {% cache globally %}
              {% nav author in craft.users({ group: 'blogAuthors', order: 'firstName', limit: null }) %}
                  <option value="{{ url('blog/author/'~author.username) }}"
                  {% if craft.request.getLastSegment() == author.username %}selected{% endif %}>
                  {{ author.name | title }}
                  </option>
              {% endnav %}
          {% endcache %}
  </select>
  
  ```
  
  **Tags:** cache
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-11-16. Score: 2 | Accepted answer
  
  This is exactly what caching is supposed to do... flatten the Twig code down to basic HTML, and serve that up instead of dynamically rendering it. Using `globally` means that the HTML would be identical on every page, which is not really what you want here.
  
  Get rid of `globally`, so it can cache separately for each page. Since the URL is supposed to affect how that snippet is rendered, you don't want to cache `globally`.
  
  
  ---
  
  