I have no idea what your actual setup is, but I general find that a best practice is to utilize embeds for control features as well as consistency. Here is an example: Two template groups, one call embeds
, one called pages
.
- Embeds
- index.html (unused)
- _header.html
- _footer.html
- Pages
- index.html
- random_template.html
Your pages
template will all look like this:
{embed="embeds/_header"}
Whatever you want in here, cochise.
{embed="embeds/_footer"}
and then your _header.html
template looks like this:
{if logged_out && segment_1 != "login"}
{if segment_1 == "account" && segment_2 == "password"}
<!-- don't redirect, we're on a password reset request page -->
{if:elseif segment_1 == "account" && segment_2 == "reset_password"}
<!-- don't redirect, we're on a the actual page were you set a new password -->
{if:else}
<!-- not logged in and not trying to reset password -->
{redirect="login"}
{/if}
{/if}
<!DOCTYPE html>
<html language="en">
<head>
<!-- and so on -->
In this example, any user that is not logged in gets forced to the log in page, and it automatically will be processed on every page you embed your header on. I'm not familiar with layouts really so this may not apply perfectly. Also this example works for an application where registration is closed and users are manually registered by an admin; you could just add some extra conditionals to allow for a registration page.