You could do something like this:
{# Grab all entries with a body > 100 %}
{% for entry in craft.entries.section('artists').order('RAND()').find() if entry.body|length > 100 %}
{# Limit output to the first 4 #}
{% if loop.index1 <= 4 %}
{{ entry.id }}'s body field has a length greater than 100!<br />
{% endif %}
{% endfor %}
Keep in mind that if entry.body
is a Rich Text field than any HTML markup (<p>
, <span>
, etc.) will be included in that length count as well.
Twig doesn't have a break
or continue
tag natively, but if you install the MN Break and Continue plugin, you can make it a bit more efficient:
{# Grab all entries with a body > 100 %}
{% for entry in craft.entries.section('artists').order('RAND()').find() if entry.body|length > 100 %}
{% if loop.index1 > 4 %}
{% break %}
{% endif %}
{{ entry.id }}'s body field has a length greater than 100!<br />
{% endfor %}