the problem here is that this will not help when your variable content gets only available later in the process, after the scriptlet runs.
as an example, we want to set the snapd deb version included in the core snap as an attribute of the version string of the snap (i.e. 16-2.45.3-git16513). the information for that version string is only available at the very end of the process where we currently can not run any scripts anymore.
so here we either need a scriptlet that runs later or (as suggested above) a variable that simply overrides any existing version string when set.