Answers.Body: <p>There's no problem re-using a variable name from a technical point of view. There is likely a problem elsewhere in your code.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-14T07:14:00.483Z
Answers.Text: Thanks @khalwat. I shall have to review that template and see where it is different from the others. I'm intrigued though why the cache clearing causes a problem in one case and not the other. Hopefully I will find the reason in the code.
Answers.UserDisplayName: Jack McKenzie
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-13T23:41:51.013Z
Answers.LastActivityDate: 2017-09-13T23:41:51.013Z
Answers.UserDisplayName: andrew.welch
Body: <p>I have this line</p>
  
  <pre><code>{% set entries = craft.entries.section('x') etc etc %}
  </code></pre>
  
  <p>Which I use to pull data for a header in my _layout.html template.</p>
  
  <p>Then later, knowing I am done with the array, inside a block in an another template which extends _layout I have </p>
  
  <pre><code>{% set entries = craft.entries.section('y') etc etc %}
  </code></pre>
  
  <p>In fact I have reused the 'entries' name regularly through many templates and a number of sites and haven't, as far as I know, had a problem, except in one case.</p>
  
  <p>In this case if the cache has just been cleared (manually at least) then the second setting of entries does not work and it contains the values from the first set, mucking up the page of course. </p>
  
  <p>On reloading the page, and subsequently until the cache is cleared manually every thing works as expected (although I don't know what happens when the cache automatically clears as I am never sure when that has just happened).</p>
  
  <p>It was an easy fix just to change 'entries' to 'whatevers' in the second line, and where it is referred to in the rest of the template.</p>
  
  <p>Is it bad practice to do what I have done (before the change), or is it likely that there is another error in my code that is causing this problem?</p>
  
Tags: <templating><set><craft.entries>
Title: Is it bad practice to re-use array variable name?
ThreadText: # Is it bad practice to re-use array variable name?
  
  (Asked by: username_0 on 2017-09-13)
  
  I have this line
  
  ```
  {% set entries = craft.entries.section('x') etc etc %}
  
  ```
  
  Which I use to pull data for a header in my \_layout.html template.
  
  Then later, knowing I am done with the array, inside a block in an another template which extends \_layout I have
  
  ```
  {% set entries = craft.entries.section('y') etc etc %}
  
  ```
  
  In fact I have reused the 'entries' name regularly through many templates and a number of sites and haven't, as far as I know, had a problem, except in one case.
  
  In this case if the cache has just been cleared (manually at least) then the second setting of entries does not work and it contains the values from the first set, mucking up the page of course.
  
  On reloading the page, and subsequently until the cache is cleared manually every thing works as expected (although I don't know what happens when the cache automatically clears as I am never sure when that has just happened).
  
  It was an easy fix just to change 'entries' to 'whatevers' in the second line, and where it is referred to in the rest of the template.
  
  Is it bad practice to do what I have done (before the change), or is it likely that there is another error in my code that is causing this problem?
  
  **Tags:** templating, set, craft.entries
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-09-13. Score: 3
  
  There's no problem re-using a variable name from a technical point of view. There is likely a problem elsewhere in your code.
  
  > **Comments:**
  > **username_0**: Thanks @khalwat. I shall have to review that template and see where it is different from the others. I'm intrigued though why the cache clearing causes a problem in one case and not the other. Hopefully I will find the reason in the code.  
  
  ---
  
  