code: def ifdef(parser, token):
      
      block_tokens = ('elifdef', 'else', 'endifdef')
      # {% ifdef ... %}
      bits = token.split_contents()[1:]
      if len(bits) > 1:
          raise TemplateSyntaxError('%r is not an identifier.' % token)
      condition = IfDefParser(bits).parse()
      nodelist = parser.parse(block_tokens)
      conditions_nodelists = [(condition, nodelist)]
      token = parser.next_token()
  
      # {% elifdef ... %} (repeatable)
      while token.contents.startswith('elifdef'):
          bits = token.split_contents()[1:]
          if len(bits) > 1:
              raise TemplateSyntaxError('%r is not an identifier.' % token)
          condition = IfDefParser(bits).parse()
          nodelist = parser.parse(block_tokens)
          conditions_nodelists.append((condition, nodelist))
          token = parser.next_token()
  
      # {% else %} (optional)
      if token.contents == 'else':
          nodelist = parser.parse(block_tokens[-1:])
          conditions_nodelists.append((None, nodelist))
          token = parser.next_token()
  
      # {% endifdef %}
      assert token.contents == 'endifdef'
  
      return IfNode(conditions_nodelists)
docs: Check if variable is defined in the context.
  
      Similar to django.template.defaulttags.do_if.