Working with template suggestions on Drupal 8
You can implement the new hook_theme_suggestions_HOOK_alter() hook.


  Alters named suggestions for a specific theme hook.
  
  This hook allows any module or theme to provide altenative theme function or template name suggestions and reorder or remove suggestions provided by hook_theme_suggestions_HOOK() or by earlier invocations of this hook.


You can use it like so

function MYMODULE_theme_suggestions_page_alter(array &amp;$suggestions, array $variables) {
  if (\Drupal::request()-&gt;query-&gt;get('foo') == 'bar') {
    $suggestions[] = 'page__myCustomTpl';
  }
}


You can implement it in either a module or theme