The entity is always set, so it needs no guard; a copy passed into a partial under another name does.
The entity object is the page's primary content record: the article, blog post, form, folder, or other type that this URL is about. It is always set, so you do not need {% if entity is_valid %} (or a similar guard) before {{ entity }}, {{ entity.title }}, {{ entity.has_url }}, or other root entity properties; that test is always true and the guard is dead code. Output them directly. Use object_type when you need to branch on what kind of entity the page is.
The guard belongs on other variables, including a copy of entity passed into a partial under another name. For example {% include '/sections/item_content.liquid' item:entity %} and then, in that section, {% if item.is_valid %} … {% endif %}. Optional fields on entity still need is_valid or default; that is a check on the field, not on entity itself, and you branch on a property only when that property is itself optional. For shared properties, {{ entities }} and {% entities %}, see Entity under Content.
ExampleCheck entity or value type with if and object_typeUse if/elsif with object_type or type checks to branch on entity or value type.
Liquid
{%- if entity.object_type == 'tag' -%}
I am a tag
{%- elsif entity.object_type == 'author' -%}
I am an author
{%- elsif entity.object_type == 'folder' -%}
I am a folder
{%- else -%}
What am I?
{%- endif -%}
ExampleOutput the type of an unknown variableUse the object_type filter to get the type of an unknown property or variable.
Liquid
{%- blog_post post = "post" -%}
{{- post | object_type -}}
{{- post | object_type: true }}
Output
blog_post
object
ExampleUse a post_date or date-time field with the date filterUse a post_date or other date-time field and format or compare it with the date filter and date properties.
Liquid
{%- if entity.rehearsal_start.is_valid -%}
<p>Rehearsal will begin on {{ entity.rehearsal_start | date: "MMMM dd, yyyy 'at' h:m t" }} UTC</p>
{%- endif -%}