fix string replacement for nested template paths