Add ability to insert template at specified index

Sometimes, it's handy not to only append or prepend a template to a content, but to insert it at a specified index, for example when implementing sorting.