You need some sort of add-on creation - that is just how XF manages it.
But in super simple steps one way of doing this is:
1. Put XF in debug mode
2. Go to development tools
3. Go to code event listneres and add a listener
4. In 'Listen to Event', choose 'Template Create'
5. In 'event hint', choose 'PAGE_CONTAINER'
6.In Execute Call back put a rerference to your code file eg 'myAddOn_Listener' would equate to /library/myAddOn/Listener.php
7 In the medthod box (after the "::") put your function called, eg 'listen'
8 put you code in the file - take note of the Callback Signature info, you need it, eg
public static function listen(&$templateName, array &$params, XenForo_Template_Abstract $template)
// do some code