To see an example of how to handle output check out:
Default Output Files in Templates