Merge pull request #1476 from ussuri/addl-rework-in-templates.dart

Moved global template vars from templates.dart to spark.dart
WIP: Further rework of templates.dart to simplify things (currently broken)