1

I know I can set postLoginRedirect in config/general.php to send the user to a specific page after login. Is there a way to grab that value in the template? This came up because I noticed that the {{siteUrl}} href in the default _layout.html template was sending the user to the homepage (index.html), but I'd like to conditionally replace that link for a logged-in user.

1 Answer 1

3

Sure, something like this should work (untested):

<a href="{{ currentUser ? url(craft.config.get('postLoginRedirect')) : siteUrl }}">Home</a>

The above should create an absolute URL to whatever's in your postLoginRedirect config setting, relative to your siteUrl.

Note that if you want an URL relative to your Control Panel (e.g. "dashboard"), you'll want to use cpUrl() instead, i.e.

<a href="{{ currentUser ? cpUrl(craft.config.get('postLoginRedirect')) : siteUrl }}">Home</a>
2
  • Just noticed that with 'postLoginRedirect' => 'dashboard' using the solution above makes the postLoginRedirect a relative link, so it doesn't work on sub-pages. Can you think of a solution besides hard coding an absolute link like 'postLoginRedirect' => '/dashboard'
    – Keith
    Commented Feb 17, 2016 at 23:16
  • @Keith You're correct – just updated the answer with a solution. Commented Feb 17, 2016 at 23:22

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.