-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathlocations_variable_generator.html
More file actions
61 lines (54 loc) · 2.33 KB
/
Copy pathlocations_variable_generator.html
File metadata and controls
61 lines (54 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{% comment %}
locations_variable_generator.html (locations_array):
Create a javascript variable for use in the function adding map markers.
Accepts Liquid array object and converts it to a javascript list
of dictionaries (JSON). This will be used for chapters and events(posts) maps.
If array of posts (events) is provided we get the event's address, latitude,
longitude etc. from the FIRST sponsor object (if more than one are present
for an event) Sponsor is a equivalent of a foreignkey for the event.
One must remember though that sponsor is just a name not a reference to
the sponsor object.
This we find among sponsors using "where" filter as below.
This is to avoid duplication of records in our yml section.
Parameters:
locations_array: Liquid array
A Liquid array containing locations to convert to javascript array
of dictionaries. Can contain only 1 element.
Returns:
locations: JSON
Javascript array of dictionaries with locations' details.
Further info:
To generate an array:
{% assign chapters = "" | split: ',' %}
{% for chapter in site.chapters %}
{% assign chapters = chapters | push: chapter %}
{% endfor %}
But it should be enough to use site.chapters or site.posts etc.
{% endcomment %}
<script>
var locations = [
{% for location in include.locations_array %}
{% if location.is_post %}
{% assign host_sponsor_id = location.sponsor %}
{% assign host_sponsor = site.sponsors | where:"obj_id", host_sponsor_id | first %}
{% capture prefix %}
"address": "{{ host_sponsor.address }}",
"lat": {{ host_sponsor.lat }},
"lng": {{ host_sponsor.lng }},
{% endcapture %}
{% else %}
{% capture prefix %}
"address": "{{ location.address }}",
"lat": {{ location.lat }},
"lng": {{ location.lng }},
{% endcapture %}
{% endif %}
{
{{ prefix }}
"title": "{{ location.title }}",
"meetupURL": "{{ location.meetup_link }}",
"URL": "{{ location.url }}",
},
{% endfor %}
];
</script>