Do the condition in the plugin then just spit out the output. Don't put the condition into the template like you are trying to do.
Ah, okay, what tripped me up originally (that's what I was trying to do at first) was that the part I'm trying to replace has several variables with apostrophes - do I just escape those in a str_replace?