Fix scope in templates