It seems that what you want is normally formulated as a callback: instead of a variable %section_10% you should look for a mechanism to call a subroutine: [% section(10) %] or so.
I don't know offhand which template modules support that mechanism, but maybe Reverse Callback Templating might be of interest to you.