1

Does anyone know why currentUser would return null? I'm logged in as an admin.. actually the only user.

I've cleared cache, logged out and back in, etc. I can't seem to get it to work.

I'm trying to set an edit link for an entry like so:

{% if currentUser %}
    <a href="{{ entry.cpEditUrl }}">
        Edit
    </a>
{% endif %}

And also tried this:

{% if entry.isEditable() %}
    <a href="{{ entry.cpEditUrl }}">
        Edit
    </a>
{% endif %}

Neither are working. Any ideas?

  • Is this in the context or a normal template request? i.e. you're not doing something edge case like trying to add this code inside of a redirect Twig tag or something similar? – Brad Bell Aug 24 '16 at 18:16
  • Normal template request. It was working fine the other day. I have looked through all my git commits, turned off plugins, etc and I cannot get it working again. – Erik Aug 24 '16 at 18:38
  • Hate to ask the obvious, but you're positive you're logged in? – Brad Bell Aug 24 '16 at 18:49
  • Yes, absolutely positive. – Erik Aug 24 '16 at 18:56
  • Did you happen to update Craft between the time it was working and now? If so, do you remember the version you were on? – Brad Bell Aug 24 '16 at 18:57
2

Per Brad's request. I am answering my own question.

I figured out that I was logging in via non-www, and accessing the site at www.

So the official answer is to choose either www or non-www. I chose to remove the www from the URL.

Here's my .htaccess for that, including allowing for fonts to be accessed cross domain, as I had issues with this as well.

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Remove www
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

    # Send would-be 404 requests to Craft
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
    RewriteRule (.+) index.php?p=$1 [QSA,L]
</IfModule>

<FilesMatch "\.(eot|ttf|otf|woff|svg)">
    Header set Access-Control-Allow-Origin "*"
</FilesMatch>

Note!!! Once this is done, make sure to clear your Craft cache., especially if using fonts/font-icons.

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.