more error checking in cms_selflink
minor fix to unique template naming.