How to use service renderer with context theme? I have snippet code: 

//Load block view (have override template)
$block = Block::load('views_block_1480647185');

// get render array
$render = \Drupal::entityTypeManager()
  -&gt;getViewBuilder('block')
  -&gt;view($block);

// get markup string
$markup = \Drupal::service('renderer')
  -&gt;render($render);

kint($markup);


when i visit different url admin (example.com/admin/content), non-admin (example.com). Value markup is different.

In example.com/admin/content



In example.com (use override template view)



I think because url use different theme (bartik and seven).

So how can set markup value same value in url non-admin? How can do that with drupal service renderer?
Use the theme.manager service to set the active theme to what you desire, render the block and set the original active theme back.

/** @var \Drupal\Core\Theme\ThemeInitialization $theme_initialization */
$theme_initialization = \Drupal::service('theme.initialization');
$active_theme = \Drupal::theme()-&gt;getActiveTheme();
\Drupal::theme()-&gt;setActiveTheme($theme_initialization-&gt;getActiveThemeByName($theme));
// Render your block...
\Drupal::theme()-&gt;setActiveTheme($active_theme);