How can I compare the results of currentUser and entry.author on an entry page? I've tried the following, but none of these get a positive result:

{% if  currentUser == 'entry.author.id' %}


{% set author %}{{ entry.author.id }}{% endset %}
{{ author }}
{% if currentUser.id == '{{ author }}' %}

(I'm aiming to provide a way for the author of an entry to be presented with a form to edit the entry)


Try this:

{% if currentUser.id == entry.author.id %}

When using quotation marks, it means that it's a string in Twig. What you want to do is compare the value of the actual variable.

Also, currentUser is a UserModel, so you need to get the id property to compare it with entry.author.id.

  • Yes, that works although I'm sure I tried it! – Andrew Mar 21 '18 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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