Templates are fetched en-masse at the start of execution. This is referred to as the "template cache". You need to add your templates to the $globaltemplates array to get your templates as well. Templates that are not cached will be fetched on request, using a query for every template.