Fixed bug in template selector

The template selector could ignore the result of the selectorfunction. 
This has been fixed.