Question: I hope the problem is clear. Is there an alternative way not to get undefined reference error without implementing template functions in header files? Thanks in advance.

Answer: 
I ended up implementing a [micro-CMS called Hardwired](http://hardwiredcms.com) that does an excellent job of staying out of my way. 

Give it a try.
Maybe you could combine a git wrapper for editing, etc:

<https://github.com/schacon/ruby-git>

with your own rendering code based on a simple file based storage system.

I'm not so familiar with Ruby though, so can't help much on the ruby rendering side of things.

This comment you make "most of my site will contain advanced dynamic functionality" looks like you are going to need to roll your own solution based on your unique requirements.