For #25252 - Fixes edge-case bug in as_template_fields.

The edge case is when the entity relationship is out of order (e.g. the Step folder is at the root) and there is a concrete match between template and path.  This resulted in the fields being partially populated in the first phase of resolution which then caused problems in the second phase!  It was more complicated than it sounds...