Publish location for a slot item on item being database published?

How do I get the publish location for a slot item on am item that is being published to a database?

For Example:

There is a slot on are press releases called ‘Image_Teaser’ we are publishing out the need information for are press releases that will be used by another application. We need to also have the url of where the image that could be in the ‘Image_Teaser’ slot got published (will get published) to so we came put it in the database publish.

That is do this in the bindings area.

Hi Jay

In the same way you get the published location of any item

$rx.location.generate($sys.assemblyItem, ‘rffBnYourBinaryTemplate’)

You’d need to publish this to a column in your database and then reference it in your your script code.

Cheers
James

location generate wants 6 params.

$rx.location.generate(templateinfo,item,folderPath,filter,siteid,context)

Also how does

$rx.location.generate($sys.assemblyItem, ‘rffBnYourBinaryTemplate’)

get a slot item to generate its publish location? Its not referencing the slot at all.

Hi Jay

Are you database publishing the entire full page template?

Cheers
James

Jay,

The $rx.location.generate binding function has two signatures (“versions”). One of these signatures (the one James mentioned) only takes an assembly item and a target Temple. The other signature takes the parameters you cite and is used when you want more control over the output URL. See pp. 424-25 of the Rhythmyx Implementation Guide.

For details about using the function, in the same document, see “complex Snippets”, p. 145.

RLJII

No jimbo,

We are only publishing out some of the information from Press releases namely:

Display title
the press releases url
url of image in the ‘image_teaser’ slot
(this maybe empty or have more then one, just need one)
the teaser info
its date
siteID
what news group its in
department
division

to separate columns in a sql table have it all working exept getting the ‘image_teaser’ slot item pub location.

thanks rljohnson for the explanation!

This is how we have been getting are urls for the items we are database publishing.

$row.url is last and that gets us are url for the press release we are publishing but I just can’t figure out how to get the image_url for the item in the ‘image_teaser’ slot for the database published press release.

Example from Bindings:

$siteItemsQuery =

“SELECT top 1 * FROM RXSITEITEMS WHERE PUBOPERATION = ‘publish’ AND PUBSTATUS = ‘success’ AND SITEID <> 321 AND
VARIANTID = 707 and CONTENTID =”+$sys.item.getProperty(“rx:sys_contentid”).String+" ORDER BY PUBDATE DESC"

$siteItemLocations =

$rx.db.get(’’,$siteItemsQuery)

$row.url =

$rx.asmhelper.mapValues($siteItemLocations,“LOCATION”)

While we are not publishing to the database, we had need to do something like this (read rss feeds). Our solution was to use some java substring magic to figure out what the url is. (ie set the rx.doc.extractBody to a variable, then depending on if the snippet template contains an image or url, get the src / href attributes). There may be a cleaner hack…but this worked marvels for us…

Of course this means that you have to have the “correct” template rendered in the slot (and by correct i mean something that has a link to the item in question).

Ok that sounds like a plan, and I will give that a shot.

Can you give me anymore tips on how you did this?

      Thanks

Let me give you more information about my particular problem:
I am using an auto indexer (A) to generate an rss feed of say people § in a particular folder (X). Each person may or may not have an image (I) in a particular slot (S). What i want to do is in the rss feed, use the enclosure tag to have the correct link to the image (I).

I know that the image snippet allowed in (S) will be a specific template with only one img src tag… So i can do the following in the page template:


## $currItem is the node in the auto indexer(A)
#set($currItemAssemblyItem = $sys.assemblyItem.clone())##
$currItemAssemblyItem.setNode($currItem)##
##find slot and get the items in the slot
#set($imgslotitems  =  $rx.asmhelper.assemble($currItemAssemblyItem,$sys.asm.findSlotByName("myImageSlotforPerson"),$blank))##
#foreach($imgItem in $imgslotitems)##
#set($imgNode = $imgItem.getNode())##
## extract the template in the slot. In this case it should be the image snippet
#set($imgURLtoParse = $rx.doc.extractBody($imgItem))##
## now to extract the url from the snippet template
## take index of src= (use 5 to get the " as well)
#set($t1 = $tools.math.add($imgURLtoParse.indexOf("src="),5))##
#set($s1 = $imgURLtoParse.substring($t1))##
## since we know that the src will contain a closing " we find the index of
## that and what remains will be the url to the image
#set($t2 = $s1.indexOf('"'))##
#set($imgItemURL = $s1.substring(0,$t2))##
## make sure that the link to the img is a full url
#if($imgItemURL.indexOf("http")!=0)##
#set($imgItemURL = "${pageSiteBase}${imgItemURL}")##
#end## $url.indexOf..
  <enclosure url="${imgItemURL}" length="$imgNode.getProperty('rx:img1_size').String" type="$imgNode.getProperty('rx:img1_type').String" />
#end## foreach $imgitem

Now i realize the above code is over kill for want you want in particular…
what you probably want in the bindings is something like this (someone may have a more elegant solution (read regex) that could do this on one line i suppose…but i am no regex guru)


$row.IMGURL = 
---------------------- set the above binding to be (assuming you have IMGURL as the column name)----- 
$returnstr="";
$firstSlotItem = $user.psoSlotTools.getSlotContents($sys.assemblyItem,
"Image_Teaser", null).get(0);
$imgURLtoParse = $rx.doc.extractBody($firstSlotItem);
$t1 = $tools.math.add($imgURLtoParse.indexOf("src="),5));
if($t1 > 3){
$s1 = $imgURLtoParse.substring($t1));
$t2 = $s1.indexOf('"'));
$returnstr = $s1.substring(0,$t2));
};
$returnstr;
------------------------

A couple of notes:

  • I don’t know if the above code will work…it is hypothetical!!!
  • I am getting what should be the first item in the slot (http://forum.percussion.com/showthread.php?t=229&highlight=item+slot) i think the function should be .node() (as opposed without the parens) but as I don’t know if the code works, you may not need the parens.
  • you will probably need to tweek it some more…if you do, i think others would benefit from a final working solution…
  • you may want the full url (ie add the site base in front of the url: ($pageSiteBase = $rx.location.siteBase($pageSiteID,“no”); )
  • did i mention that i haven’t tested the code above? :slight_smile:

Hope this gets you started in the correct path…

I am giving this a shot, I will let you know how it goes.

 Thanks!

I am getting an error :

Error reported

Unexpected exception while assembling one or more items: Problem when evaluating expression “$user.psoSlotTools.getSlotContents($sys.assemblyItem,“Image_Teaser”, null).getNode(0);” for variable “$firstSlotItem”: Could not find method getNode for object [[]] and arguments [0]

Does anyone have an idea as to what is wrong?

If I don’t use the .getNode(0) then I get this error:

Error reported

Unexpected exception while assembling one or more items: Problem when evaluating expression “$rx.doc.extractBody($firstSlotItem);” for variable “$imgURLtoParse”: Could not find method extractBody for object [com.percussion.services.assembly.jexl.PSDocumentUtils@16ce580] and arguments [[]]

Here is my binding code:

$firstSlotItem = 
$user.psoSlotTools.getSlotContents($sys.assemblyItem,"Image_Teaser", null).node

$imgURLtoParse = 
$rx.doc.extractBody($firstSlotItem);

$t1 = 
$tools.math.add($imgURLtoParse.indexOf('src="'),5);

$row.imgUrl = 
if($t1 > 3){  $s1 = $imgURLtoParse.substring($t1);  $t2 = $s1.indexOf('"');  $s1.substring(0,$t2);  };else{""};

try using just .get(0) as opposed to getNode() (this is because what you get back is (i believe) a java list…and the method getNode() does not exist for a java list)

you might need to use .get(0).getNode() to get the actual node to pass on though…but i might be mistaken (i would be under the impression that what you get back will be enough, without you calling getNode() b/c of what $rx.doc.extractBody() takes in)…

When I use the .get(0) I get this error:

Error reported

Unexpected exception while assembling one or more items: Problem when evaluating expression “$user.psoSlotTools.getSlotContents($sys.assemblyItem,“Image_Teaser”, null).get(0);” for variable “$firstSlotItem”: Index: 0, Size: 0

ANd for .get(0).getNode() I get this error:

Error reported

Unexpected exception while assembling one or more items: Problem when evaluating expression “$user.psoSlotTools.getSlotContents($sys.assemblyItem,“Image_Teaser”, null).get(0).getNode();” for variable “$firstSlotItem”: Index: 0, Size: 0

Oh…well do you have items in that slot?
I would check the size first (probably size()), and then if you have more than 0 items, get(0)…
ie:


$list = $user.psoSlotTools.getSlotContents($sys.assemblyIt em,"Image_Teaser", null)

$firstItem = 
if($list.size() > 0 ) {
$list.get(0);
}


Jit

$list = $user.psoSlotTools.getSlotContents($sys.assemblyItem,"Image_Teaser", null)

$list seems to always be an empty list for all press releases and there should only be about 10% of the 2100 press releases that are that way. All the other have images in the ‘Image_Teaser’ slot.

Does anyone know what is going on?

I assume that you have tried this on an actual (say html produced template) page where when you call the slot macro (say #slot_simple(‘Image_Teaser’)) you will get an image from that? And on that note i assume that you have this on each press release (as opposed to indexing the press releases?)?

If so, another way to get the slot (which may be what psoSlotTools uses) is:


$list  =  $rx.asmhelper.assemble($sys.assemblyItem,$sys.asm.findSlotByName("Image_Teaser"),$blank))##

Thanks jitendra,

That almost has it but I am getting a wierdness in the publish. Some of the image urls are coming out fine (getting full url) and others are just the file name from the url.

This might be from the 2 different content types that are aloud to be in this slot both of which are images. I will give an update when I figure it out.

What you might want to do is get the full url (including the site name regardless). Are the images with only the filename because those are at the root of your site?

The way you can get the full url is via:


#set($pageSiteID = $rx.asmhelper.getSingleParamValue($sys.params,'sys_siteid'))##
#set($pageSiteBase = $rx.location.siteBase($pageSiteID,"no"))##

Then check for an “http” at the begining of the file name, if none exists, then append $pageSiteBase

We have no images in the root of the site. An Example would be

contentID:24898

location of image at:http://www.mysiteAsExample.com/Image/Images/ImageTeasers/CATCH/Praying_Boy.jpg

but getting as the location:Praying_Boy.jpg

I can’t seem to find an answer to why this is happening.