code: def _build_template(
      name: str,
      template: jinja2.Template,
      files: Files,
      config: MkDocsConfig,
      nav: Navigation,
  ) -> str:
      """Return rendered output for given template as a string."""
      # Run `pre_template` plugin events.
      template = config.plugins.on_pre_template(
          template, template_name=name, config=config
      )
  
      if utils.is_error_template(name):
          # Force absolute URLs in the nav of error pages and account for the
          # possibility that the docs root might be different than the server root.
          # See https://github.com/mkdocs/mkdocs/issues/77.
          # However, if site_url is not set, assume the docs root and server root
          # are the same. See https://github.com/mkdocs/mkdocs/issues/1598.
          base_url = urlsplit(config.site_url or "/").path
      else:
          base_url = utils.get_relative_url(".", name)
  
      context = get_context(nav, files, config, base_url=base_url)
  
      # Run `template_context` plugin events.
      context = config.plugins.on_template_context(
          context, template_name=name, config=config
      )
  
      output = template.render(context)
  
      # Run `post_template` plugin events.
      output = config.plugins.on_post_template(
          output, template_name=name, config=config
      )
  
      return output
  
imports: from __future__ import annotations
  import gzip
  import logging
  import os
  import time
  from typing import TYPE_CHECKING, Sequence
  from urllib.parse import urljoin, urlsplit
  import jinja2
  from jinja2.exceptions import TemplateNotFound
  import mkdocs
  from mkdocs import utils
  from mkdocs.exceptions import Abort, BuildError
  from mkdocs.structure.files import File, Files, InclusionLevel, get_files, set_exclusions
  from mkdocs.structure.nav import Navigation, get_navigation
  from mkdocs.structure.pages import Page
  from mkdocs.utils import DuplicateFilter
  from mkdocs.utils import templates
label_desc: Use image node_id 2 for calling a global function with example usage: _build_template(name, template, files, config, nav) and returns: output