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

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

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

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

CC BY-SA 4.0
2018-12-06T06:44:22.230Z
2018-12-06T06:44:22.230Z
Brad Bell
<p>I want to create a login page.  It would be a Single. </p>

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

<p>I tried: </p>

<ul>
<li>creating a login folder under templates.  </li>
<li>naming the twig file either <code>login.twig</code> or <code>index.twig</code></li>
<li>setting the template location to <code>login/login.twig</code> or <code>login/index</code></li>
</ul>

<p>Neither approach worked. </p>

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

<templating><singles>
How do I setup the Login Page to work with requireLogin?
# How do I setup the Login Page to work with requireLogin?

(Asked by: username_0 on 2018-12-05)

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?

**Tags:** templating, singles


---

## 1 answers

### Answer by username_1 on 2018-12-06. Score: 1

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.


---

