umm, yeah, i was having this problem! but, ill show you how 2 fix it ^^
all of your script, that you want to appear,
only do it for your suctom part, the stuff at the top, it alwasy works ^^
PHP Code:
$name_your_template_code = ob_get_contents();
ob_end_clean();
now, go to oyur template and where you want the code to appear, type: $name_your_template_code
if you get stuck, lme know...