Sorting of a Simple Loop
If your template is a succession of nested loops, which return and receive variables (that do not matter) and if you want to sort on a terminal data, follow this recommendation.
Accessing linked objects of the same nature such as products and subproducts, suits to this situation.
Example: Get Physical Products
In the following example, the template lets you get physical products and their subproducts. You want to provide them alphabetically by title.

If you place the sorting by reference title at the child level, the result is not the expecting one.
Create a shortcut method to define a single loop instead of two loops:
PACKAGE PLM; METHOD VPMReference.getSubProductReferences() -doc : SubProducts.GetReferencePLMReference[EACH ISA VPMReference] LABEL "SubProduct References";
You can use this method in your template, and then place the sorted title on this loop,
as follows: 

