2

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?

1 Answer 1

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.

1
  • 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. Commented Sep 14, 2017 at 7:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.