code: def _parse_template(self, has_content):
          
          reset = self._head
          context = contexts.TEMPLATE_NAME
          if has_content:
              context |= contexts.HAS_TEMPLATE
          try:
              template = self._parse(context)
          except BadRoute:
              self._head = reset
              raise
          self._emit_first(tokens.TemplateOpen())
          self._emit_all(template)
          self._emit(tokens.TemplateClose())
docs: Parse a template at the head of the wikicode string.