I would like to have multiple markers on the same map with Symfony and UX Map! I've read the documentation but can't find the solution there! At the moment, I can get all the markers but on different maps with this code:
<div class="map">
{% for signalement in signalements %}
{{ ux_map(
center : [47.65, 1.50],
zoom: 7,
markers: [
{
position: [signalement.structure.latitude, signalement.structure.longitude],
title: signalement.structure.nom
},
],
attributes: {
class: 'mapimap',
style: 'height: 35rem; width: 30rem',
}
)
}}
{% endfor %}
</div>
I need to be able to loop only the markers part, but I don't see how to do it!
Thanks A.L. for your reply! I tried it myself, but it doesn't work :(
I get this error message:
A mapping key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token “operator” of value “%”.
Here's what I did:
<div class="map">
{{ ux_map(
center : [47.65, 1.50],
zoom: 7,
{% set markers = [] %}
{% for signalement in signalements %}
{% set markers = markers|merge([{
'position' : [signalement.structure.latitude, signalement.structure.longitude],
'title' : signalement.structure.nom
}])
%}
{% endfor %}
attributes: {
class: 'mapimap',
style: 'height: 35rem; width: 30rem',
})
}}
</div>
Or maybe I didn't understand the reply correctly or used it wrong :(
{% set … %}and{%for … %}blocks before{{ ux_map(, you can't write Twig code in a Twig tag like this. Also, you never pass themarkerstoux_map. I added an example in the answer.