XF 1.5 New template variable


I'm trying to find tutorial for adding a new template variable to thread_view template. Ok, maybe it's a too "high" goal, but i need to understand the structure of php code, where template variables are initialized. This far i managed to create a class and functions for custom bbcode wich has callback function. So i want more :)

What i want is:
- i want a button for each post in a thread, if user id has a specific value,
- load a javascript in header wich has a function for button click,

Can anyone guide me to some tutorials?

Thank you.