Bug still persists, but fixed on the outside:
When clicking on template links, the $('#'+key)'s key always defaults to the last one (in a test with 4 different templates)
Yet $(this).attr('id'), which gets the id of the link, returns the correct value

There are possible workarounds