Take the 2-minute tour ×
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

I'm trying to return entries where a specific field named "productSale" is not empty. Unfortunately, my code attempts keep throwing the "Expected name or number" error.

Code attempts include:

{% set products = craft.entries.section('product').productSale.(':notempty:').find() %}
{% set products = craft.entries.section('product').productSale.('not null').find() %}
{% set products = craft.entries.section('product').productSale.('is not null').find() %}
{% set products = craft.entries.section('product').productSale.('not empty').find() %}

Three questions then:

  1. What is the "Expected name or number" error saying exactly?
  2. Where in the available docs (Craft or Twig) would I look for explanation on this? I didn't find much in my first pass.
  3. How do I return entries where a specific field is "not empty"
share|improve this question
1  
Try removing the dot after productSale: productSale(':notempty:') –  Victor In Jun 24 at 22:20
    
Oh, FFS! Thank you. –  Anna_MediaGirl Jun 24 at 22:24
    
Do you know where in the docs I can find ":notempty:"? –  Anna_MediaGirl Jun 24 at 22:26
    
Glad I could help, I'll added it as an answer. –  Victor In Jun 24 at 22:28

1 Answer 1

up vote 4 down vote accepted

1. "Expected name or number" error

The parser is expecting a method/property after the dot of productSale, but you are passing arguments. Removing the dot to make it valid:

{% set products = craft.entries.section('product').productSale(':notempty:') %}

.

2. Documentation

There is no documentation on this yet, but it is listed in the release notes:

Added support for passing “:empty:” and “:notempty:” to ElementCriteriaModel parameters when you’re looking for empty/non-empty values.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.