Updated TemplateGenerator.pm to perform better

When there are a large number of activated DynamicFields the TemplateGenerator would become extremely CPU intensive even if you don't use any DynamicFields in your templates.

This patch makes it so the only DynamicFields loaded are ones referenced in the template, removing the overhead of simply having DynamicFields.