As far as I know you can't create templates in code.
The rest can be gleaned from browsing the wowpedia site for script code examples.
Here is the HOWTO page that provides a few examples of what you might want to do in addons, there are a few frame related examples which will hopefully get you started.
https://wow.gamepedia.com/HOWTOs
And this link gets you to the CreateFrame page with some additional examples:
https://wow.gamepedia.com/API_CreateFrame
Is there a reason you need this in lua format ?