I want to create a login page. It would be a Single.

The URI is set to login. So how do I name and map the twig file?

I tried:

  • creating a login folder under templates.
  • naming the twig file either login.twig or index.twig
  • setting the template location to login/login.twig or login/index

Neither approach worked.

How do I setup a login page so that when I use requireLogin the login page is in the right location for loginPath. At the bare minimum, where is the easiest location to place the login path?

You didn't specify Craft 2 or 3, but I'm pretty sure this answer applies to both.

The template should live at templates/login/index.twig or templates/login.twig. Craft will resolve to both of them.

I tested this on a fresh Craft Pro install and created a Single with a template path of login. There is a templates/login.twig with the login example here: https://docs.craftcms.com/v3/dev/examples/login-form.html and a templates/test.twig that only has {% requireLogin %} in it.

I logged out of Craft, then went to mysite.com/test in a browser and was successfully redirected to mysite.com/login that rendered the example login template.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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