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?

8
  • 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
    Commented Aug 24, 2016 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
    Commented Aug 24, 2016 at 18:38
  • Hate to ask the obvious, but you're positive you're logged in?
    – Brad Bell
    Commented Aug 24, 2016 at 18:49
  • Yes, absolutely positive.
    – Erik
    Commented Aug 24, 2016 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
    Commented Aug 24, 2016 at 18:57

1 Answer 1

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 and acknowledge you have read our privacy policy.

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