I’ve created the following macros to enable me to include assembled content from arbitrary content items within the templates of other items.
## macro to create an assembly item from scratch.
## Sam Rushing, July 31, 2009
#macro(createAssemblyItem $asmItem $contentid $revision $templateName $params)##
#set( $asmItem = $sys.asm.createAssemblyItem() )##
$asmItem.setTemplate($sys.asm.findTemplateByName( $templateName ))##
$asmItem.setJobId( $sys.assemblyItem.getJobId() )##
$asmItem.setVariables( $sys.assemblyItem.getVariables() )##
#set( $tempparams = $rx.asmhelper.combine($sys.params,$params) )##
$asmItem.setParameters( $rx.asmhelper.combine($tempparams,"sys_contentid=${contentid}&sys_revision=${revision}") )##
$asmItem.normalize()##
#end
## macro to assemble a manually created assembly item and return the results
## Sam Rushing, July 31, 2009
#macro(assembleItem $assemblyResult $assemblyItem)##
#set( $assemblyResult = $sys.asm.assemble( [$assemblyItem] ).get(0).toResultString() )##
#end
## macro to autonomously assemble an item from its content ID, revision, template name and additional parameters
## Sam Rushing, July 31, 2009
#macro(assemble $contentid $revision $templateName $params)##
#createAssemblyItem( $asmItem $contentid $revision $templateName $params )##
#assembleItem( $result $asmItem )##
$result##
#end
There are probably better was of doing this, but as an example, I’ve used these macros to build navigation panels for some subcategory preview templates (where subcategories are associated to categories by adding them to a slot in the parent category – yes, I know this is a bit strange, but we needed to have an easy way to force an order on the subcategories.):
#set( $contentid = $sys.item.getProperty('rx.sys_contentid').string )
#set( $category = $rx.db.get( '', "select s.contentid, s.editrevision from psx_objectrelationship r, contentstatus s where r.owner_id = s.contentid and ((s.editrevision = -1 and r.owner_revision = s.currentrevision) or (s.editrevision <> -1 and r.owner_revision = s.editrevision)) and r.dependent_id = $contentid").get(0) )
<div class="page-content">
<div class="navigation-panel">
#assemble( $category.get('CONTENTID') $category.get('EDITREVISION') 'Category_Nav_Preview' "highlight=$contentid" )
</div>
<div class="content-body">
...
</div>
</div>