Take a look to this thread Adding `output` function to buttons designed in `template` node.
You may feel that there is too many posts to follow but the problem under the discussion same as yours. So take a time to read and do experiments, I 'm sure you can find solution from it.