code: def do_if_has_tag(parser, token, negate=False):
      
      bits = list(token.split_contents())
      if len(bits) < 2:
          raise TemplateSyntaxError("%r takes at least one arguments" % bits[0])
      end_tag = 'end%s' % bits[0]
      has_tag = all([tag in parser.tags for tag in bits[1:]])
      has_tag = (not negate and has_tag) or (negate and not has_tag)
      nodelist_true = nodelist_false = CommentNode()
      if has_tag:
          nodelist_true = parser.parse(('else', end_tag))
          token = parser.next_token()
          if token.contents == 'else':
              parser.skip_past(end_tag)
      else:
          while parser.tokens:
              token = parser.next_token()
              if token.token_type == TOKEN_BLOCK and token.contents == end_tag:
                  return IfNode([
                      (Literal(has_tag), nodelist_true),
                      (None, nodelist_false)
                  ])
              elif token.token_type == TOKEN_BLOCK and token.contents == 'else':
                  break
          nodelist_false = parser.parse((end_tag,))
          parser.next_token()
      return IfNode([(Literal(has_tag), nodelist_true),
                     (None, nodelist_false)])
docs: The logic for both ``{% if_has_tag %}`` and ``{% if not_has_tag %}``.
  
      Checks if all the given tags exist (or not exist if ``negate`` is ``True``)
      and then only parses the branch that will not error due to non-existing
      tags.
  
      This means that the following is essentially the same as a
      ``{% comment %}`` tag::
  
        {% if_has_tag non_existing_tag %}
            {% non_existing_tag %}
        {% endif_has_tag %}
  
      Another example is checking a built-in tag. This will always render the
      current year and never FAIL::
  
        {% if_has_tag now %}
            {% now "Y" %}
        {% else %}
            FAIL
        {% endif_has_tag %}