<p>There are multiple ways to achieve your goal, I think the most elegant one is to overwrite the default route <code>/users</code> with your custom one and replace the <code>elementType</code></p>

<p><strong>Things you need to do</strong> </p>

<ol>
<li>Change the default route to your template</li>
<li>Copy the default template and change it's element type</li>
<li>Create a custom element type that extends <code>craft/elements/User</code></li>
</ol>

<p>You can change the route of all <a href="https://docs.craftcms.com/v3/updating-plugins.html#plugin-hooks" rel="nofollow noreferrer">navigation</a>  bar items (modifyCpNav)</p>

<pre><code>Event::on(
    Cp::class, 
    Cp::EVENT_REGISTER_CP_NAV_ITEMS, 
    function(RegisterCpNavItemsEvent $event){
        // the 4th element is the "User", you can change the URL to your
        // custom template instead of the default template
        // I suggest you to loop all `navItems` and find 
        // the correct user instead of assuming it's the 4th
        // Craft::dd($event-&gt;navItems);
        $event-&gt;navItems[4]['url'] = 'path/to/template/user';
});
</code></pre>

<p>Then just copy the Craft <code>templates/user/index</code> template in your plugin to create an <a href="https://docs.craftcms.com/v3/element-types.html#index-page" rel="nofollow noreferrer">index page</a></p>

<pre><code>{% if CraftEdition != CraftPro %}
    {% exit 404 %}
{% endif %}

{% requirePermission 'editUsers' %}

{% extends "_layouts/elementindex" %}
{% set title = "Users"|t('app') %}
// changes start
// replace the elementType with your custom element type
{% set elementType = 'prefix\\namespace\\elements\\User' %}
// changes end
{% block actionButton %}
    {% if currentUser.can('registerUsers') %}
        &lt;a class="btn submit add icon" href="{{ url('users/new') }}"&gt;{{ "New user"|t('app') }}&lt;/a&gt;
    {% endif %}
{% endblock %}
</code></pre>

<p>Then in your <code>src/elements</code> folder create a new User class to overwrite the <a href="https://docs.craftcms.com/v3/element-types.html#sources" rel="nofollow noreferrer">sources</a></p>

<pre><code>class User extends \craft\elements\User{ //&lt;-- extend the default User element

    /**
     * @inheritdoc
     */
    protected static function defineSources(string $context = null): array
    {
        $sources = [
            [
                'key' =&gt; '*',
                'label' =&gt; Craft::t('app', 'All users'),
                'criteria' =&gt; ['status' =&gt; null],
                'hasThumbs' =&gt; true
            ]
        ];

        // Overwrite the sources / usergroups...
        // usually Craft will search for usergroups at this place..
        // just leave it empty, so you'll only see the "default" group

        return $sources;
    }
}
</code></pre>

<p>Don't forget to <a href="https://docs.craftcms.com/v3/updating-plugins.html#element-hooks" rel="nofollow noreferrer">register</a> your element</p>

<p><strong>TL/DR</strong><br>
You could as well just hide the other sources via CSS/Javascript - but I would not suggest it, since everyone is able to see the other groups with minor Javascript skills</p>

CC BY-SA 4.0
2018-05-27T00:46:09.153Z
A few questions... Couldn't a user with a little knowledge of Craft go directly to the old admin/users page? I had an issue with $event->navItems[4]['url'] = ['template' => 'path/to/template/user'], it seems to want a text value, not an array. I replaced with $event->navItems[$x]['url'] = 'user2'; and that works.
Eric Snyder
CC BY-SA 4.0
2018-05-27T00:51:25.270Z
Oh yeah it must be a route, I was one step too far. You can overwrite the route directly instead of changing the url as well since dynamic routes are resolved before template routes https://docs.craftcms.com/v3/routing.html
Robin Schambach
CC BY-SA 4.0
2018-05-27T01:01:50.910Z
I don't seem to be able to override an admin route in the Routes section of the control panel?
Eric Snyder
CC BY-SA 4.0
2018-05-27T08:52:48.650Z
Yes you are not, but you can do it with a Plugin
Robin Schambach
CC BY-SA 4.0
2018-05-30T01:42:15.473Z
Having issues with the template. I added src/templates/users2/index.html and the logic that changes the url to the user page to 'users2'. I am getting a template not found error.
Eric Snyder
CC BY-SA 4.0
2018-05-30T05:16:42.163Z
You need to define a route https://docs.craftcms.com/v3/updating-plugins.html#routing-hooks or include your plugin handle
Robin Schambach
CC BY-SA 4.0
2018-05-26T23:06:18.773Z
2018-05-27T00:47:33.187Z
2018-05-27T00:47:33.187Z
Robin Schambach
<p>I want to override the admin/users page template when a plug in is installed.</p>

<p>Detail:
On the user page domain.com/admin/user all the groups are listed in the sidebar area. I get this from the \vender\craftcms\cms\src\templates_layouts\cp.html file. I want to install/use use a custom template for the user page using a plug in.</p>

<p>What are the basics of overriding a admin template through a plugin?</p>

<p><strong>Edit - More detail:</strong></p>

<p>I have a plugin that creates a new controller exactly the way that is proposed in <a href="https://craftcms.stackexchange.com/questions/25698/restrict-permissions-per-entry-rather-than-per-section">this post</a>. The controller does two things (maybe more later):</p>

<p>1) On entries page it displays all the entries to a logged in user that was posted by them and others from their same group. It does not display entries that were posted by users in other groups.</p>

<p>2) On user page it displays only users from their own group. It does not display any other users from other groups.</p>

<p>On the users page all the groups are listed here:</p>

<p><a href="https://i.sstatic.net/jhzyS.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/jhzyS.png" alt="enter image description here"></a></p>

<p>It does not make sense to display all the groups here as the logged in user can only see or edit users in their own group.</p>

<p>I need to change what is displayed in the group listing area.</p>

CC BY-SA 4.0
2018-05-26T20:58:31.523Z
Basically you can overwrite the entire CP, If you want to create an entirely new interface in your CP you can do that as well. There is nothing you can't change/overwrite but we can't answer the question unless we know what you are trying to achieve in detail
Robin Schambach
<plugin-development><templating><craft3>
Basics of overriding an admin page template - Craft 3
# Basics of overriding an admin page template - Craft 3

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

I want to override the admin/users page template when a plug in is installed.

Detail:
On the user page domain.com/admin/user all the groups are listed in the sidebar area. I get this from the \vender\craftcms\cms\src\templates\_layouts\cp.html file. I want to install/use use a custom template for the user page using a plug in.

What are the basics of overriding a admin template through a plugin?

**Edit - More detail:**

I have a plugin that creates a new controller exactly the way that is proposed in [this post](https://craftcms.stackexchange.com/questions/25698/restrict-permissions-per-entry-rather-than-per-section). The controller does two things (maybe more later):

1) On entries page it displays all the entries to a logged in user that was posted by them and others from their same group. It does not display entries that were posted by users in other groups.

2) On user page it displays only users from their own group. It does not display any other users from other groups.

On the users page all the groups are listed here:

[![enter image description here](https://i.sstatic.net/jhzyS.png)](https://i.sstatic.net/jhzyS.png)

It does not make sense to display all the groups here as the logged in user can only see or edit users in their own group.

I need to change what is displayed in the group listing area.

**Tags:** plugin-development, templating, craft3

> **Comments:**
> **username_1**: Basically you can overwrite the entire CP, If you want to create an entirely new interface in your CP you can do that as well. There is nothing you can't change/overwrite but we can't answer the question unless we know what you are trying to achieve in detail  

---

## 1 answers

### Answer by username_1 on 2018-05-26. Score: 2 | Accepted answer

There are multiple ways to achieve your goal, I think the most elegant one is to overwrite the default route /users with your custom one and replace the elementType
Things you need to do 

Change the default route to your template
Copy the default template and change it's element type
Create a custom element type that extends craft/elements/User

You can change the route of all navigation  bar items (modifyCpNav)
Event::on(
    Cp::class, 
    Cp::EVENT_REGISTER_CP_NAV_ITEMS, 
    function(RegisterCpNavItemsEvent $event){
        // the 4th element is the "User", you can change the URL to your
        // custom template instead of the default template
        // I suggest you to loop all `navItems` and find 
        // the correct user instead of assuming it's the 4th
        // Craft::dd($event->navItems);
        $event->navItems[4]['url'] = 'path/to/template/user';
});

Then just copy the Craft templates/user/index template in your plugin to create an index page
{% if CraftEdition != CraftPro %}
    {% exit 404 %}
{% endif %}

{% requirePermission 'editUsers' %}

{% extends "_layouts/elementindex" %}
{% set title = "Users"|t('app') %}
// changes start
// replace the elementType with your custom element type
{% set elementType = 'prefix\\namespace\\elements\\User' %}
// changes end
{% block actionButton %}
    {% if currentUser.can('registerUsers') %}
        {{ "New user"|t('app') }}
    {% endif %}
{% endblock %}

Then in your src/elements folder create a new User class to overwrite the sources
class User extends \craft\elements\User{ //<-- extend the default User element

    /**
     * @inheritdoc
     */
    protected static function defineSources(string $context = null): array
    {
        $sources = [
            [
                'key' => '*',
                'label' => Craft::t('app', 'All users'),
                'criteria' => ['status' => null],
                'hasThumbs' => true
            ]
        ];

        // Overwrite the sources / usergroups...
        // usually Craft will search for usergroups at this place..
        // just leave it empty, so you'll only see the "default" group

        return $sources;
    }
}

Don't forget to register your element
TL/DR
You could as well just hide the other sources via CSS/Javascript - but I would not suggest it, since everyone is able to see the other groups with minor Javascript skills

> **Comments:**
> **username_0**: A few questions... Couldn't a user with a little knowledge of Craft go directly to the old admin/users page? I had an issue with $event->navItems[4]['url'] = ['template' => 'path/to/template/user'], it seems to want a text value, not an array. I replaced with $event->navItems[$x]['url'] = 'user2'; and that works.  
> **username_1**: Oh yeah it must be a route, I was one step too far. You can overwrite the route directly instead of changing the url as well since dynamic routes are resolved before template routes https://docs.craftcms.com/v3/routing.html  
> **username_0**: I don't seem to be able to override an admin route in the Routes section of the control panel?  
> **username_1**: Yes you are not, but you can do it with a Plugin  
> **username_0**: Having issues with the template. I added src/templates/users2/index.html and the logic that changes the url to the user page to 'users2'. I am getting a template not found error.  
> **username_1**: You need to define a route https://docs.craftcms.com/v3/updating-plugins.html#routing-hooks or include your plugin handle  

---

