I have several templates I'd like to use a close button template on.
I have the close button template with a template parameter of currentWindow. Here is the script I have applied to the button.
But the system function is definitely preferred - first, you don't have to do any awkward importing, and second it takes care of some extra threading niceties and error messaging for you.