1

I have a Dynamic Blitz template with a currentUser if statement within it. For some reason, it's not working and I can't figure out why.

It gets loaded in as follows:

{{ craft.blitz.getTemplate('brands/_followButton', { elementId: entry.id }) }}

The code on the page running it:

 {% if currentUser %}
  {% if craft.follow.check({ elementId: entry.id }) %}
    <a class="btn btn-sm btn-light py-2 px-3 mr-2" rel="nofollow" href="{{ craft.follow.unfollowUrl(entry.id) }}"><span class="material-icons mr-2 md-18">favorite</span>Unfollow</a>
  {% else %}
    <a class="btn btn-sm btn-light py-2 px-3 mr-2" rel="nofollow" href="{{ craft.follow.followUrl(entry.id) }}"><span class="material-icons mr-2 md-18">favorite_border</span>Follow</a>
  {% endif %}

  {% else %}
    <a class="btn btn-sm btn-light py-2 px-3 mr-2" rel="nofollow" href="/register"><span class="material-icons mr-2 md-18">favorite_border</span>Follow</a>
{% endif %}
  • 1
    If you hit the _followButton template template directly does it show correctly? – RitterKnight Nov 9 '20 at 18:47
  • @RitterKnight What do you mean sorry? – JMKelley Nov 10 '20 at 15:45
  • The partial loads perfectly when I'm not logged in. – JMKelley Nov 10 '20 at 17:36
1

Your code looks correct. Test with the following code in brands/_followButton.

{{ currentUser ? 'Logged in' : 'Logged out' }}

For some reason, it's not working and I can't figure out why.

Can you explain what specifically is not working? And provide the version of Blitz that you're using?

  • Removing the follow button code within the partial and replacing it with the above renders "Logged In" and "Logged Out" in both states fine. So it must come down to the "followCheck" and entry.id. – JMKelley Nov 11 '20 at 21:31
0

Fixed by using

  {% if craft.follow.check({ elementId: elementId }) %}

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.