How to detect the model type of an item in an array of query results When querying multiple model types (entries, Commerce products and Commerce variants) I want to be able to detect the model type of each item as I iterate over the results array.

Ideally to avoid this sort of error:

Craft\EntryModel and its behaviors do not have a method or closure named


There doesn't seem to be a clean way of doing this but I may be wrong!
Twig doesn't have a native "instanceof" check, but it'd be pretty trivial to create a simple plugin that added a Twig Extension where you can add an instanceof test.

public function getTests()
{
    return array(
        'instanceof' =&gt;  new \Twig_Function_Method($this, 'isInstanceof')
    );
}

public function isInstanceof($var, $instance)
{
    return  $var instanceof $instance;
}


Then from your template, you'd do something like:

{% if value is instanceof('Commerce_ProductModel') %}