A different template based on a taxonomy term in views
You can define each template by using template 
page--taxonomy--term--xxx.html.twig 
where xxx is your term id.

In your code, $term-&gt;getVocabularyId();
will return machine name of vocabulary, not the term id. It mean all term of this vocabulary will use this template.