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?

1 Answer 1


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.

  • 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. Commented Sep 28, 2017 at 8:50
  • 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
    Commented Sep 28, 2017 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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