reorganize if clause in template for better understanding