The templatecache string uses single quotes, so unless you are careful where you put it, you're probably creating mismatched quotes.
ETA: unless you're saying that test that you're replacing is in a double-quoted string? That's why I asked where it was. Do you have a way to print out the templatecache string so you can see it? I think if you print it out before and after your replace, you'll probably be able to see what the problem is.
|