add sorting to templates