Need to Sort a Print Format of the Picklist based on Field "Warehouse" In "Item Locations" Table

Hello,

We need to Sort a Print Format of the Picklist based on Field “Warehouse” In “Item Locations” Table. Read a bit about Jinja templating, etc. but not been able to do it.

Also added custom HTML as below but it threw an error:
{% for item in doc.item_locations|sort(attribute=‘warehouse’) %}… {% endfor %}

Can anyone help with this sorting requirement in the print format and how this can be done and where is the code to be inserted? Appreciate the help.

Thanks.

Which error does it threw?