Measurement of the charge asymmetry in top quark pair production in pp collisions at s =8 TeV using a template method