Answers.Body: <p>Not sure if I totally got it but you can check the class of an object via</p>
  
  <pre><code>{% if element is instance of ('craft\\elements\\Entry') %}
  </code></pre>
  
  <p>or via <code>switch</code> statement</p>
  
  <pre><code>{% switch className(element) %}
      {% case 'craft\\elements\\Entry' %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-13T12:44:44.957Z
Answers.Text: Thanks Robin - that pretty much works. Follow up question to improve my own knowledge.... how would I have been able to work that out from the docs? Also, how would I query "if element is calendar entry"?
Answers.UserDisplayName: darylknight
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-13T13:54:44.717Z
Answers.Text: About the docs thing: I don't know - since it is more or less basic/common PHP knowledge I'm not sure if it has so much to do with the docs. Craft docs are not supposed to cover those things. Not sure what the other thing should mean. You can always only query for one element type, there is no way to inlcude such a condition since it's always the case
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-13T15:42:14.073Z
Answers.Text: Docs are only meant to cover common problems and be a reference (e.g. the className() function is documented here: https://docs.craftcms.com/v3/dev/functions.html#classname-object). That said we are working on a new Guides section for craftcms.com for less common things, and this could very well be something we put in there.
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-14T06:31:46.923Z
Answers.Text: Thanks you two - yeah, the functions reference is handy. Robin - worked it out. What I was testing for other than Entry was `{% case "Solspace\\Calendar\\Elements\\Event" %}`, which I found using `entry.className`
Answers.UserDisplayName: darylknight
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-13T12:16:23.833Z
Answers.LastActivityDate: 2018-08-13T12:16:23.833Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I'm trying to plot entries from two different Solspace Calendars and an Entries section on one map, and use different markers for all types. Alll of the events are related to the current Entry through a field set on the Event, and a field set on the Entry. I have:</p>
  
  <ul>
  <li>E Waste - Solspace Calendar</li>
  <li>Community Events - Solspace Calendar</li>
  <li>Disposal Sites - Craft Entry</li>
  </ul>
  
  <p>All three of those above have address fields, and I'll be plotting them on a Smart Map. Currently, I'm doing this:</p>
  
  <pre><code>{# Get all eWaste events related to material #}
  {% set eWaste = craft.calendar.events({
  calendar: 'eWaste',
      relatedTo: [ 'or', { targetElement: entry.materialCategory }, { targetElement: entry } ],
      rangeStart: now|date('Y-m-d'),
      rangeEnd: now|date_modify('+3 months')
  }) %}
  
  {# Get related sites #}
  {% set sites = craft.entries.section('sites').relatedTo([ 'or', { targetElement: entry.materialCategory }, { targetElement: entry }]) %}
  
  {# Merge events and entries #}
  {% set locations = eWaste|merge( sites ) %}
  
  {{ craft.smartMap.map(locations, options) }}
  </code></pre>
  
  <p>That gets events from one calendar, and the entries in to a single array so I can plot them on one map, but I can't work out how to differentiate between the types in order to give them different markers. As an example, <code>entry.type</code> doesn't work, and neither does <code>{% if entry.eventField is defined %}</code></p>
  
  <p>Am I going about this the wrong way? How do I achieve what I'm after? Will the above approach also work for two different calendars + entries?</p>
  
Tags: <templating><craft3><plugin-smartmap><plugin-solspacecalendar>
Title: How do I differentiate between entries after merging an array?
ThreadText: # How do I differentiate between entries after merging an array?
  
  (Asked by: username_0 on 2018-08-13)
  
  I'm trying to plot entries from two different Solspace Calendars and an Entries section on one map, and use different markers for all types. Alll of the events are related to the current Entry through a field set on the Event, and a field set on the Entry. I have:
  
  * E Waste - Solspace Calendar
  * Community Events - Solspace Calendar
  * Disposal Sites - Craft Entry
  
  All three of those above have address fields, and I'll be plotting them on a Smart Map. Currently, I'm doing this:
  
  ```
  {# Get all eWaste events related to material #}
  {% set eWaste = craft.calendar.events({
  calendar: 'eWaste',
      relatedTo: [ 'or', { targetElement: entry.materialCategory }, { targetElement: entry } ],
      rangeStart: now|date('Y-m-d'),
      rangeEnd: now|date_modify('+3 months')
  }) %}
  
  {# Get related sites #}
  {% set sites = craft.entries.section('sites').relatedTo([ 'or', { targetElement: entry.materialCategory }, { targetElement: entry }]) %}
  
  {# Merge events and entries #}
  {% set locations = eWaste|merge( sites ) %}
  
  {{ craft.smartMap.map(locations, options) }}
  
  ```
  
  That gets events from one calendar, and the entries in to a single array so I can plot them on one map, but I can't work out how to differentiate between the types in order to give them different markers. As an example, `entry.type` doesn't work, and neither does `{% if entry.eventField is defined %}`
  
  Am I going about this the wrong way? How do I achieve what I'm after? Will the above approach also work for two different calendars + entries?
  
  **Tags:** templating, craft3, plugin-smartmap, plugin-solspacecalendar
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-08-13. Score: 4 | Accepted answer
  
  Not sure if I totally got it but you can check the class of an object via
  
  ```
  {% if element is instance of ('craft\\elements\\Entry') %}
  
  ```
  
  or via `switch` statement
  
  ```
  {% switch className(element) %}
      {% case 'craft\\elements\\Entry' %}
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks username_1 - that pretty much works. Follow up question to improve my own knowledge.... how would I have been able to work that out from the docs? Also, how would I query "if element is calendar entry"?  
  > **username_1**: About the docs thing: I don't know - since it is more or less basic/common PHP knowledge I'm not sure if it has so much to do with the docs. Craft docs are not supposed to cover those things. Not sure what the other thing should mean. You can always only query for one element type, there is no way to inlcude such a condition since it's always the case  
  > **username_2**: Docs are only meant to cover common problems and be a reference (e.g. the className() function is documented here: https://docs.craftcms.com/v3/dev/functions.html#classname-object). That said we are working on a new Guides section for craftcms.com for less common things, and this could very well be something we put in there.  
  > **username_0**: Thanks you two - yeah, the functions reference is handy. username_1 - worked it out. What I was testing for other than Entry was `{% case "Solspace\\Calendar\\Elements\\Event" %}`, which I found using `entry.className`  
  
  ---
  
  