1

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.

1 Answer 1

3

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)} ] %}
3
  • I already tried that, however when removing the ' craft throws an error at me: Oct 21, 2016 at 9:03
  • 'A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "punctuation" of value "{".' Oct 21, 2016 at 9:03
  • That totally worked! Thank you for the super fast answer! :) Oct 21, 2016 at 9:08

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.