Answers.Body: <p>You pretty much nailed it.  </p>
  
  <p>If you have multiple pages that require an authenticated session, then have all of those pages extend a template that uses something like <a href="http://buildwithcraft.com/docs/templating/requirelogin" rel="nofollow">{% requireLogin %}</a>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-20T08:39:45.073Z
Answers.Text: Sorry I am lost here : I did a `require-login` template which extends `_layouts/site`. Then in this template I have a condition `{% if not craft.session.isLoggedIn %}` in `block main` for example. But it does not work. I should stop extending the parent template when the user is not logged in no ?
Answers.UserDisplayName: migmaker
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-20T11:01:42.523Z
Answers.Text: OK here is what I did : put a flag in the pages that need privacy '{% set requireLogin = true %}' and in `_layouts/site` (extended by all pages) I added the control `{% if (requireLogin is defined and not craft.session.isLoggedIn) %}` display the login box `else` display regular `block main`. Looks good no?
Answers.UserDisplayName: migmaker
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-19T19:58:33.090Z
Answers.LastActivityDate: 2015-09-19T19:58:33.090Z
Answers.UserDisplayName: Brad Bell
Body: <p>I made a member area with multiple pages in a <code>member-area</code> template folder.<br>
  I d like to protecte all pages in this folder.  </p>
  
  <p>I know the <code>isLoggedIn</code> function to protect a page in a twig template.<br>
  <a href="http://buildwithcraft.com/docs/templating/craft.session" rel="nofollow">http://buildwithcraft.com/docs/templating/craft.session</a>  </p>
  
  <pre><code>{% if craft.session.isLoggedIn %}
      &lt;a href="{{ logoutUrl }}"&gt;Logout&lt;/a&gt;
  {% endif %}
  </code></pre>
  
  <p>But what would be the best way to protect multiple pages ?  </p>
  
  <p>Put the control on <code>_layouts/base</code> or <code>_layouts/site</code> templates?<br>
  Note: And above that problem I got an ajax login form (I can make a dedicated login page if it is more simple and no choice)</p>
  
Tags: <users><login>
Title: Protect mutliple pages in a template folder
ThreadText: # Protect mutliple pages in a template folder
  
  (Asked by: username_0 on 2015-09-19)
  
  I made a member area with multiple pages in a `member-area` template folder.  
  I d like to protecte all pages in this folder.
  
  I know the `isLoggedIn` function to protect a page in a twig template.  
  <http://buildwithcraft.com/docs/templating/craft.session>
  
  ```
  {% if craft.session.isLoggedIn %}
      <a href="{{ logoutUrl }}">Logout</a>
  {% endif %}
  
  ```
  
  But what would be the best way to protect multiple pages ?
  
  Put the control on `_layouts/base` or `_layouts/site` templates?  
  Note: And above that problem I got an ajax login form (I can make a dedicated login page if it is more simple and no choice)
  
  **Tags:** users, login
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-09-19. Score: 1
  
  You pretty much nailed it.
  
  If you have multiple pages that require an authenticated session, then have all of those pages extend a template that uses something like [{% requireLogin %}](http://buildwithcraft.com/docs/templating/requirelogin).
  
  > **Comments:**
  > **username_0**: Sorry I am lost here : I did a `require-login` template which extends `_layouts/site`. Then in this template I have a condition `{% if not craft.session.isLoggedIn %}` in `block main` for example. But it does not work. I should stop extending the parent template when the user is not logged in no ?  
  > **username_0**: OK here is what I did : put a flag in the pages that need privacy '{% set requireLogin = true %}' and in `_layouts/site` (extended by all pages) I added the control `{% if (requireLogin is defined and not craft.session.isLoggedIn) %}` display the login box `else` display regular `block main`. Looks good no?  
  
  ---
  
  