var classes = $(this).attr("class").split(/\s/);
classes[0] === 'template'
classes[1] === 'active'
If there are more than two classnames and you only want to get the first & last (that was your question) you can call:
classes[0] = first class
classes[classes.length -1] = last class