I am trying to pass a variable to a string, while the string itself is inserted into an existing array as follows:
var myVar = 'slug'; myArray.push(['item one', '/path/to/' + myVar + '/']);
This does not work at all. I see that the correct value is assigned to myVar ; however, myVar in the array is not even recognized as a variable.
It seems simple enough, but I obviously missed something.
Thank you for your help.
EDIT: not a Javascript issue.
As Alex showed, this definitely works fine. (And yes, this is an existing array.)
However, I forgot to mention that the push method is wrapped in a bit of Django template logic so that it only runs on my dev instance, for example:
{% ifequal INSTANCE 'DEVELOPMENT' %] myArray.push(['item one', '/path/to/' + myVar + '/']); {% endifequal %}
I did not mention logic because I did not see how this could interfere. I have confirmed that:
- everything with logic behaved as expected
- INSTANCE really equaled "DEVELOPMENT"
- and this Javascript line was visible in the source, which would not be if the logic were bad.
However, if I remove this Django logic, everything with Javascript will work as desired.
For some reason, this server-side logic is stopping me from passing any external values to the array, on the client or server side.
As an experiment, I tried this ...
myArray.push(['item one', '/path/to/{{ block slug }}undefined{{ endblock }}/']);
... with the following in the child template.
{{ block slug }}slug{{ endblock }}
The same thing is happening. When using template logic, the value is /path/to/undefined . Without it, the value /path/to/slug is optional.
Why this happens is a mystery to me. I can get around this, but if anyone has any thoughts, I would like to hear them.
Thanks again.
Noob side question: what is etiquette about changing message headers?