Fix template substitution with proper escapes

Change-Id: Id46b1cfd3ad841bf2c111f645ea6a2edfc43d519