Compare Value to Category Title In Template I'm new to Craft and am trying to set up a condition that will compare the value of a category (entry.position).  However, I get this error message:

Object of class Craft\ElementCriteriaModel could not be converted to string


I'm not really sure how to do a textual comparison.  The 'position' field is, in my case, a category.  How would a comparison be achieved?

I've tried this:

{% set entry_pos = entry.position %}
{#   {%  craft.categories.slug('position') %} #}                 
{{ entry_pos }}

{% if entry.position != 'staff' %}
    {% if entry.UBFUserName != '' %}
        {% set name_var = entry.UBFUserName %}
            {{ craft.aitest.AiTestVariable(name_var) }}
        {% else %}
    {% endif %}      
{% endif %}
Your entry_pos is an Element Criteria Model. You want to get the first (and probably only) category from this ElementCriteriaModel, and then compare its title to 'staff':

{% set entry_pos = entry.position.first %}
{% if entry_pos.title == 'staff' %}
  ...
{% endif %}


This will give you an error if there is no entry.position.first, as entry_pos will be null, so you should defend against that somehow. One possility is:

{% if entry_pos and entry_pos.title == 'staff' %} ...


Another is to use twigs useful null-coalescing operator:

{% if (entry_pos.title ?? '') == 'staff' %} ...


With Craft 3, you will use one instead of first, but otherwise everything is the same.