Add new exception for invalid template ref

Hopefully is clearer than a KeyError.

Change-Id: Ib387825396ab0286df00aaff3b1b539cd7fc9a77
Fixes: bug #1178011
Merge "Add new exception for invalid template ref"