Simple string replacement in views output? In Drupal 7, for a view where I wanted to replace every instance of 'am' with 'a.m.' (with a similar replacement for pm/p.m.) in the output, I did this:

function mymodule_views_post_render(&amp;$view, &amp;$output, &amp;$cache) {
  if ($view-&gt;name == 'target_view') {
    $replace_pairs = array(
      ' am ' =&gt; ' a.m. ',
      ' pm ' =&gt; ' p.m. ',
    );
    $output = strtr($output, $replace_pairs);
  }
}


How do I achieve the same result in Drupal 8? The documentation for the D8 version of hook_views_post_render() is broken/incomplete, but it does mention strtr(), so I imagine something similar should work.

I've already figured out that my if statement will need to test against $view-storage->id() instead, and I've noticed that $output is an array (rather than a string) in D8, but I'm not seeing anything appropriate to target in that array. I am new to D8; can someone show me the way?
In your custom module, create module_name.views.inc file and add following code.

&lt;?php
use \Drupal\views\ViewExecutable;
use \Drupal\views\Plugin\views\cache\CachePluginBase;

function custom_module_views_post_render(ViewExecutable $view, &amp;$output, CachePluginBase $cache) {
  if ($view-&gt;id() == 'VIEW_NAME') {
    $html = \Drupal::service('renderer')-&gt;renderRoot($output['#rows']);
    $replace_pairs = array(
      ' am ' =&gt; ' a.m. ',
      ' pm ' =&gt; ' p.m. ',
    );
    $html =  strtr($html, $replace_pairs);

    $output['#rows'] = $html;
  }
}


Replace VIEW_NAME with your view name and clear drupal cache.