<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def render_glitchgram(path, cp):
 """ Render a glitchgram file template. """


    # define filename and slug from path
    filename = os.path.basename(path)
    slug = filename.replace('.', '_')

    # render template
    template_dir = pycbc.results.__path__[0] + '/templates/files'
    env = Environment(loader=FileSystemLoader(template_dir))
    env.globals.update(abs=abs)
    template = env.get_template(cp.get(filename, 'template'))
    context = {'filename' : filename,
               'slug'     : slug,
               'cp'       : cp}
    output = template.render(context)

    return output