$rx.location.generate($sys.assemblyItem) generated link NOT right when published

The following is the main part of the page template which calls macro #assemble() Sam Rushing developed in http://forum.percussion.com/showthread.php?7757-Macros-to-assemble-arbitrary-content-items-inside-other-templates. I used PHP for the Velocity code simply because “CODE” won’t display HTML tags

#set($sqlAbstracts = "select de.contentid absID, de.public_revision absRev from psx_objectrelationship po where .....")

#set( $abstracts = $rx.db.get("", $sqlAbstracts) )
#foreach( $abstract in $abstracts)
    #assemble($abstract.get('ABSID') $abstract.get('ABSREV') 'intraSnAbstractTD' '' $asmAbstract)

Snippet template intraSnAbstractTD has code snippet like

#set($abstract_title = $sys.item.getProperty("abstract_title").String.trim())
#set($link = $rx.location.generate($sys.assemblyItem))

<td><a href="$link">$abstract_title</a></td>
<td><img src="$imglink" alt="$img_alt" $!img_h_att $!img_w_att /></td>

The logic is quite simple: the SQL query returns rows of desired contentid/revision which feed into macro #assemble(), which then calls snippet template intraSnAbstractTD to generate the right HTML code. The page content item resides under /admin/. when I preview the page which displays a list of abstracts (title/image/text/…), links on the abstracts render fine. However, after I published the content item, the target page displays all abstract links as /admin/index.htm. Clearly there is something NOT right with $rx.location.generate($sys.assemblyItem)

Any idea to fix the issue?

Thanks, Hua


I hope you’ve solved this on your own but in case not… I’ve used Sam’s code successfully (THANKS, Sam!) and I’m not sure why you’re having problems. I assume you’ve modified his #assemble macro since you pass an additional parameter. I am guessing you use $asmAbstract to hold the ‘intraSnAbstractTD’ output for additional processing before displaying. However, you don’t indicate what you do to $asmAbstract. If you’re not adding anything to the snippet template output, why not save a line, use Sam’s original signature, and wrap the macro call in the table-row tagset?

#foreach( $abstract in $abstracts)
    <tr>#assemble($abstract.get('ABSID') $abstract.get('ABSREV') 'intraSnAbstractTD' '')</tr>

As to the publish link being different from the preview, that sounds more like a location scheme issue with Context > Site_Folder_Assembly. When you preview an item (where links are working) change the browser URL parameter ‘sys_context’ from 0 (preview context) to 1 (publish context) and view the page source to see what the assembled links look like and maybe that will give you more troubleshooting info. HTH

Thanks Bernadette for your response -

I used Sam’s macro in other places and it works perfect. The scenario here is a little bit different. I copied the final response from Percussion Tech Support here. Eventually I have to pass in the folder path in the assemble() as a parameter like

#assemble($abstract.get('ABSID') $abstract.get('ABSREV') 'intraSnAbstractTD' "abslink=$abstract.get('ABSPATH')" $asmAbstract)

This causes links NOT work in Preview but work when published

Hello Hua,
This is a summary of our meeting this afternoon: we concluded that you need to extract the folder path of the abstract when you retrieve them for assembly, and bind it to a variable to use in the href value of the link. Given that there are no parent folder passed in this assembly context, $rx.location.generate method will assemble the links in relation to the parent page. Thus, sys.pub_path will resolve to the parent page path.
I am now closing this case per our discussion.