Template render error: The "loop.last" variable is not defined when looping with a condition.