def METHOD_NAME(manifest_template, enabled_conditions):
  regexp = re.compile(PREPROCESSOR_IF_REGEXP, re.MULTILINE)
  while True:
    match = regexp.search(manifest_template)
    if not match:
      break
    # Get the condition - the text written inside ${if}.
    condition = match.group(1)
    # Get the body - the text between ${if} and ${endif}.
    conditional_body = match.group(2)
    # Get the remaining text before/after this ${if}/${endif} block.
    all_before = manifest_template[:match.start()]
    all_after = manifest_template[match.end():]
    # Replace the ${if}/${endif} block depending on whether the condition is
    # enabled or not.
    manifest_template = '{all_before}{replacement}{all_after}'.format(
        all_before=all_before,
        replacement=conditional_body if condition in enabled_conditions else '',
        all_after=all_after)
  return manifest_template