Properly check $templates array