I basically wrote the second part of the code for you. Cellarius wrote a really good article that you may be interested in -
[vB4] Rendering templates and registering variables - a short guide That will help you understand that part of the code.
I would still not do it your way. I'd just include the code in the php file instead of in an outsite file, but that is up to you.