       save_label: "Upload"
       render_complete: (parent_template) ->
         parent_template.$("#modal-dialog-save").on("click", (event) ->
-          insert_image_save_func(parent_template,
+          template = window.image_upload_template
+          if !template?
+            return
+          insert_image_save_func(template,
                send_coll, my_id, "images")
         )
 

    else
      handle_file_step_two( chosen_file, template )

Template.InsertImageDialog.created = ->
  @selected_files = new ReactiveVar()
  @selected_files.set([])


my_uploader = null # variable local to this script
uploader_state_changed = new Deps.Dependency
upload_progress_dialog = null

# global
window.image_upload_template = null

# ---- Template.binary_data_from_id_block -------------

