I can't really help without seeing your code. But, I can tell you that you cannot use echo statements. You need to assign your output to a variable and output that variable into the template.
I suspected that was the case. I saw an article here on assigning a template to a variable to use in another template.