def replace_var_to_value()

in solutions_builder/cli/vars.py [0:0]


def replace_var_to_value(var_name, var_value, text):
  overall_count = 0

  # Replace simple variable pattern with sb-var:var_name
  text, count = replace_var_to_template(var_name, text)
  overall_count += count

  # Replace custom-content variable pattern with sb-var:var_name:custom_template
  text, count = replace_var_to_template(var_name, text, custom_template=True)
  overall_count += count

  # Update variables using Jinja2
  jinja_env = jinja2.Environment()
  text = text.replace("# copier:raw", "# copier:raw{% raw %}")
  text = text.replace("# copier:endraw", "# copier:endraw{% endraw %}")
  template = jinja_env.from_string(text)

  # Set vars data for jinja
  data = {}
  data[var_name] = var_value

  # Apply variable values using Jinja2
  text = template.render(**data)

  # Restore vars to template in comment.
  text, count = restore_template_in_comment(var_name, var_value, text)

  return (text, overall_count)