You should use a macro (http://twig.sensiolabs.org/doc/tags/macro.html) to generate each li this will avoid the ~20 lines of {% set %}