I want to hide all tabs (local tasks) for non-admin users except the tabs on the user account page (for example, I want to hide tabs on nodes of all content types).
To hide the tabs, I added a check for admin permission in my theme template: templates/menu/menu-local-tasks.html.twig
{% if user.hasPermission('administer nodes') %}
{% if primary %}
<h2 class="visually-hidden">{{ 'Primary tabs'|t }}</h2>
<ul class="tabs--primary nav nav-tabs">{{ primary }}</ul>
{% endif %}
{% if secondary %}
<h2 class="visually-hidden">{{ 'Secondary tabs'|t }}</h2>
<ul class="tabs--secondary pagination pagination-sm">{{ secondary }}</ul>
{% endif %}
{% endif %}
This works, but it hides the tabs on the user account page as well.
I tried to find a more specific template of menu-local-tasks
for the user account. I turned on twig debugging, but these were the suggestions:
<!-- FILE NAME SUGGESTIONS:
* block--mytheme-local-tasks.html.twig
x block--local-tasks-block.html.twig
* block--core.html.twig
* block.html.twig
-->
All of these affect the entire site; there is no way to target just the user account local tasks.
Is there a way to do this with theme templates? I chose this approach rather than trying to unset the local tasks in a hook because in a template you can do it in just a line or two of code.