Referencing child pub locations in velocity.

I’m rebuilding an old 5.7 application as a 6.5 Velocity template and I’m finding that our reliance on the old PSOGenerateChildPubLocation exit for publishing images from child tables is making things quite difficult.

I was, however, able to figure out how to get references to said images (for the most part) using the following code:
[ol]
[li]In the main template for the content type, use the #children macro (or something similar).
[/li][li]Then, in the child template, use code like this:
[/li]

#set( $contentId = $sys.item.getProperty('rx:sys_contentid').string )##
#set( $revisionId = $sys.assemblyItem.getParameterValue('sys_revision',$sys.item.getProperty('rx:sys_revision').string) )##
#set( $childId = $sys.assemblyItem.getNode().getUUID() )##
#set( $tmplId = $sys.asm.findTemplateByName( 'PUBLISHED_CHILD_VARIANT_NAME' ).getGUID().getUUID() )##
#set( $siteId = $sys.assemblyItem.getParameterValue('sys_siteid', '0') )##
$rx.ext.call('global/percussion/assemblers/','PSOGenerateChildPubLocation',$childId,$tmplId,$contentId,$revisionId,313,$siteId)

[/ol]

You’ll notice I had to hardcode my context id (313, in this case - since it’s different from the context to which the template will be publishing). This makes the template code a little volitile when migrating between servers. So far, I haven’t been able to find any function or method to find a context id from that context’s name in 6.5.2 that’s accessible from inside a velocity template.

Does anyone have any idea on how I could do this better, or at least to determine a context id from a context’s name?

Thanks,
– Sam