<p>Just do it with Twig by having a main template pull from two other templates based on the user group. So in your index template (or whatever template gets called), just add this at the top:</p>

<pre><code>{% if currentUser.isInGroup('customer') %}
    {% include '_dashboard/customer/settings' %}
{% else %}
    {% include '_dashboard/admin/settings' %}
{% endif %}
</code></pre>

<p>And then fill out each template however you want.</p>

<p>Conversely, you can check if the user is a CMS admin with <code>{% if currentUser.admin %}</code> and then the <code>{% else %}</code> would be for customers.</p>

CC BY-SA 3.0
2017-09-28T08:50:45.367Z
Thanks Ryan. This is a good option, however it does mean creating extra templates. Will wait to see if anyone else has any ideas before marking this as the accepted answer.
Luke Pearce
CC BY-SA 3.0
2017-09-28T13:33:39.250Z
It only adds 1 extra template: the index. It would be better to direct to `dashboard/index` and then have two templates in `dashboard/` called `_customerSettings` and `_adminSettings`.  Going your route with the controller still utilizes multiple templates.  And in addition, my way also allows you to use the index as a global template to set things the other two share so you don't repeat yourself.
Ryan
CC BY-SA 3.0
2017-09-27T19:07:45.477Z
2017-09-27T19:07:45.477Z
Ryan
<p>I'd like to have consistent URL's for an account section but depending on the current users group, the template will be different. I know I could use the same template but there would be a lot of if/else's throughout and I'd like to avoid that.</p>

<p>URL pattern would be something like this:</p>

<p>If customer group
<code>'account/settings' =&gt; '_dashboard/customer/settings'</code></p>

<p>If admin group
<code>'account/settings' =&gt; '_dashboard/admin/settings'</code></p>

<p>I was thinking this might be possible with a plugin controller that each route would hit and then decide which template to render.</p>

<p>For both groups
<code>'account/settings' =&gt; ['action' =&gt; 'action/path']</code></p>

<pre><code>function action()
{
   // Get user
   // Set path based on user group
   // Set template path to front end
   // Render template
}
</code></pre>

<p>Can you see any problems with the above solution? Will there be much of a performance hit? Is there a better way?</p>

<routes>
Use different template for same route based on user group
# Use different template for same route based on user group

(Asked by: username_0 on 2017-09-27)

I'd like to have consistent URL's for an account section but depending on the current users group, the template will be different. I know I could use the same template but there would be a lot of if/else's throughout and I'd like to avoid that.
URL pattern would be something like this:
If customer group
'account/settings' => '_dashboard/customer/settings'
If admin group
'account/settings' => '_dashboard/admin/settings'
I was thinking this might be possible with a plugin controller that each route would hit and then decide which template to render.
For both groups
'account/settings' => ['action' => 'action/path']
function action()
{
   // Get user
   // Set path based on user group
   // Set template path to front end
   // Render template
}

Can you see any problems with the above solution? Will there be much of a performance hit? Is there a better way?

**Tags:** routes


---

## 1 answers

### Answer by username_1 on 2017-09-27. Score: 2 | Accepted answer

Just do it with Twig by having a main template pull from two other templates based on the user group. So in your index template (or whatever template gets called), just add this at the top:
{% if currentUser.isInGroup('customer') %}
    {% include '_dashboard/customer/settings' %}
{% else %}
    {% include '_dashboard/admin/settings' %}
{% endif %}

And then fill out each template however you want.
Conversely, you can check if the user is a CMS admin with {% if currentUser.admin %} and then the {% else %} would be for customers.

> **Comments:**
> **username_0**: Thanks username_1. This is a good option, however it does mean creating extra templates. Will wait to see if anyone else has any ideas before marking this as the accepted answer.  
> **username_1**: It only adds 1 extra template: the index. It would be better to direct to `dashboard/index` and then have two templates in `dashboard/` called `_customerSettings` and `_adminSettings`.  Going your route with the controller still utilizes multiple templates.  And in addition, my way also allows you to use the index as a global template to set things the other two share so you don't repeat yourself.  

---

