Fixed template handling in multi-app environment

Fixes #1076