Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-09-28T19:03:11.393Z
Answers.Text: I need just remove all non-English sites from this list.
Answers.UserDisplayName: DuxaBilii
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-06-22T13:45:09.683Z
Answers.Text: Could this not be solved with permissions?
Answers.UserDisplayName: Matthias Redl-Mann
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-09-25T21:31:28.540Z
Answers.LastActivityDate: 2023-09-25T22:03:52.730Z
Answers.LastEditDate: 2023-09-25T22:03:52.730Z
Answers.UserDisplayName: RomanAvr
Body: <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>
  
Tags: <craft3><templating><control-panel>
Title: How to extend or override CP template?
ThreadText: # 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](https://craftcms.com/docs/4.x/extend/template-hooks.html#control-panel-template-hooks) for such case.
  
  But what you can try to do instead is:
  
  1. [Register JS file(s)](https://craftcms.com/docs/4.x/extend/asset-bundles.html) for the CP part of website and modify DOM elements as needed via JavaScript.
  2. 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?  
  
  ---
  
  