Add image sorting to templates