Conditional to see if an Entries field in a user profile contains a certain entry ID I've got a user profile field named Books. This is an Entries field that contains entries from the Books channel. The idea is that users will save books to their their profile to show they have read them.

I've also got a listing page which outputs all the books that are available.

I'd like to add a conditional that checks to see if the entry ID for a book is contained within the Books entries field in the current user's profile.

I've tried the following but it doesn't work. It outputs as true for every entry, even those that aren't saved to the user's profile. Any help would be appreciated, thanks.

{{ entry.title }}

{% if currentUser.booksField.contains("entry.id") %}
  I have read this book
{% else %}
  I haven't read this book
{% endif %}
My initial though was that you do not need to not put the "entry.id" in quotes because it's a variable reference, but the contains() method appear to not work as expected here even when this was corrected.

The booksField returns an ElementCriteriaModel, so you should be able to fetch the list of IDs as a plain array and then use Twig's in "containment operator" to search it:

{{ entry.title }}

{% if entry.id in currentUser.booksField.ids() %}
  I have read this book
{% else %}
  I haven't read this book
{% endif %}