<p>Well, I don't see how this can be done easily(without changing vendor files), mainly because there is no <a href="https://craftcms.com/docs/4.x/extend/template-hooks.html#control-panel-template-hooks" rel="nofollow noreferrer">CP template hook</a> for such case.</p>
<p>But what you can try to do instead is:</p>
<ol>
<li><a href="https://craftcms.com/docs/4.x/extend/asset-bundles.html" rel="nofollow noreferrer">Register JS file(s)</a> for the CP part of website and modify DOM elements as needed via JavaScript.</li>
<li>Use EVENT_BEFORE_RENDER_TEMPLATE and modify variables, of course, if it'll be useful in your case</li>
</ol>
<p>...</p>
<pre><code>use yii\base\Event;

use craft\events\TemplateEvent;

use craft\web\View;

...


Event::on(
    View::class,
    View::EVENT_BEFORE_RENDER_TEMPLATE,
    function (TemplateEvent $event) {
        if ($event-&gt;templateMode === 'cp' &amp;&amp; $event-&gt;template === '_layouts/_elements/sitemenu.twig') {
            $variables = $event-&gt;variables;
            $variables['groups'] = ...;
            $event-&gt;variables = $variables;
        }
        // ...
    }
);
</code></pre>
<p>Perhaps you can provide more context so the community can help you find a more elegant solution.</p>

CC BY-SA 4.0
2023-09-28T19:03:11.393Z
I need just remove all non-English sites from this list.
DuxaBilii
CC BY-SA 4.0
2024-06-22T13:45:09.683Z
Could this not be solved with permissions?
Matthias Redl-Mann
CC BY-SA 4.0
2023-09-25T21:31:28.540Z
2023-09-25T22:03:52.730Z
2023-09-25T22:03:52.730Z
RomanAvr
<p>I need to add some custom condition to the top siteMenu selector.</p>
<p>Template file with top menu:</p>
<blockquote>
<p>vendor/craftcms/cms/src/templates/_elements/sitemenu.twig</p>
</blockquote>
<p>Block with this menu:</p>
<blockquote>
<p>vendor/craftcms/cms/src/templates/_layouts/elementindex.twig</p>
</blockquote>
<p>How can I extend <code>elementindex.twig</code> to use my own template from module or override <code>sitemenu.twig</code> without changing any of the vendor files?</p>

<craft3><templating><control-panel>
How to extend or override CP template?
# How to extend or override CP template?

(Asked by: username_0 on 2023-09-23)

I need to add some custom condition to the top siteMenu selector.

Template file with top menu:

> vendor/craftcms/cms/src/templates/\_elements/sitemenu.twig

Block with this menu:

> vendor/craftcms/cms/src/templates/\_layouts/elementindex.twig

How can I extend `elementindex.twig` to use my own template from module or override `sitemenu.twig` without changing any of the vendor files?

**Tags:** craft3, templating, control-panel

---

## 1 answers

### Answer by username_1 on 2023-09-25. Score: 0

Well, I don't see how this can be done easily(without changing vendor files), mainly because there is no CP template hook for such case.
But what you can try to do instead is:

Register JS file(s) for the CP part of website and modify DOM elements as needed via JavaScript.
Use EVENT_BEFORE_RENDER_TEMPLATE and modify variables, of course, if it'll be useful in your case

...
use yii\base\Event;

use craft\events\TemplateEvent;

use craft\web\View;

...


Event::on(
    View::class,
    View::EVENT_BEFORE_RENDER_TEMPLATE,
    function (TemplateEvent $event) {
        if ($event->templateMode === 'cp' && $event->template === '_layouts/_elements/sitemenu.twig') {
            $variables = $event->variables;
            $variables['groups'] = ...;
            $event->variables = $variables;
        }
        // ...
    }
);

Perhaps you can provide more context so the community can help you find a more elegant solution.

> **Comments:**
> **username_0**: I need just remove all non-English sites from this list.  
> **username_2**: Could this not be solved with permissions?  

---

