<p>To output variables inside an array like that you'd simply omit the twig braces.. at the moment the <code>'</code> are telling whatever is inside them to output as a string.</p>

<p>UPDATE: try adding parentheses around each variables like so</p>

<pre><code>{'name':(entry.title),'url':(entry.Url),'lat':(entry.latitude),'lng':(entry.longitude)} ] %}
</code></pre>

CC BY-SA 3.0
2016-10-21T09:03:26.860Z
I already tried that, however when removing the `'` craft throws an error at me:
justussimon91
CC BY-SA 3.0
2016-10-21T09:03:54.927Z
`'`A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "punctuation" of value "{".`'`
justussimon91
CC BY-SA 3.0
2016-10-21T09:08:57.203Z
That totally worked! Thank you for the super fast answer! :)
justussimon91
CC BY-SA 3.0
2016-10-21T08:55:49.377Z
2016-10-21T09:05:47.653Z
2016-10-21T09:05:47.653Z
Luke Pearce
<p>I'm currently trying to call variables called <code>{{entry.title}}</code>, <code>{{entry.latitude}}</code> and so on in an array.</p>

<p>This is what it looks like:</p>

<pre><code>{% set markerArray = [] %}
{% for entry in craft.entries.section('xSpots') %}
    {% set tempMarkerArray = [
    {'name':'{{entry.title}}','url':'{{entry.Url}}','lat':'{{entry.latitude}}','lng':'{{entry.longitude}}'}
    ] %}
    {% set markerArray = markerArray|merge(tempMarkerArray) %}
{% endfor %}
</code></pre>

<p>When calling <code>{{markerArray[0].name}}</code> afterwards I am expecting it to return the proper title of the entry in Craft, instead it only returns "{{entry.title}}", as if the variable is not properly recognized while filling the array.</p>

<p>Any help? Am I doing something fundamentally wrong?
Thanks in advance.</p>

<variable><array>
Call a Craft variable inside array
# Call a Craft variable inside array

(Asked by: username_0 on 2016-10-21)

I'm currently trying to call variables called {{entry.title}}, {{entry.latitude}} and so on in an array.
This is what it looks like:
{% set markerArray = [] %}
{% for entry in craft.entries.section('xSpots') %}
    {% set tempMarkerArray = [
    {'name':'{{entry.title}}','url':'{{entry.Url}}','lat':'{{entry.latitude}}','lng':'{{entry.longitude}}'}
    ] %}
    {% set markerArray = markerArray|merge(tempMarkerArray) %}
{% endfor %}

When calling {{markerArray[0].name}} afterwards I am expecting it to return the proper title of the entry in Craft, instead it only returns "{{entry.title}}", as if the variable is not properly recognized while filling the array.
Any help? Am I doing something fundamentally wrong?
Thanks in advance.

**Tags:** variable, array


---

## 1 answers

### Answer by username_1 on 2016-10-21. Score: 3 | Accepted answer

To output variables inside an array like that you'd simply omit the twig braces.. at the moment the ' are telling whatever is inside them to output as a string.
UPDATE: try adding parentheses around each variables like so
{'name':(entry.title),'url':(entry.Url),'lat':(entry.latitude),'lng':(entry.longitude)} ] %}

> **Comments:**
> **username_0**: I already tried that, however when removing the `'` craft throws an error at me:  
> **username_0**: `'`A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "punctuation" of value "{".`'`  
> **username_0**: That totally worked! Thank you for the super fast answer! :)  

---

