# for loop sorted output in a template

**URL:** <https://forum.ansible.com/t/for-loop-sorted-output-in-a-template/23947>\
**Category:** Ansible Project\
**Created:** [March 13, 2017, 3:51am UTC](https://forum.ansible.com/t/for-loop-sorted-output-in-a-template/23947 "2017-03-13T03:51:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Spike1](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@Spike1](https://forum.ansible.com/u/Spike1)\
**Post date:** [March 13, 2017, 3:51am UTC](https://forum.ansible.com/t/for-loop-sorted-output-in-a-template/23947/1 "2017-03-13T03:51:50Z")

</div>

Hi,

I’ve had this problem came up a few times and hope someone here has a solution for it.

I have a basic for loop in a template where multiple lines are printed per loop. The problem is that I’d like similar lines to be grouped.

Example:

_myvar:_  
_- {name: one, value: 1}_  
_- {name: two, value: 2}_

_{% for v in myvar %}_  
_name is {{[v.name](http://v.name)}}_  
_val is {{v.value}}_  
_{% endfor %}_

That generates:

_name is one_  
_value is one_  
_name is two_  
_value is two_

What I would like:

_name is one_  
_name is two_

_value is two_

_value is one_

is this possible without a double loop each one containing a line?

thanks,

Spike
