Get image details from slot

Hi,

I’m trying to do something simple but can’t seem to get it working.

The idea is to get the images within a slot inside an article page and publish details to a database.

I can get the url of the image using:

(Bindings)


$etImageSlotContentImage5: $user.psoSlotTools.getSlotContents($sys.assemblyItem,‘ET_Image’,null);

Get image path:

$row.image4: if ($etImageSlotContentImage5 != ‘[]’){$rx.location.generate($etImageSlotContentImage5[0],‘etBnImage4’);}else {0;}


Now I want to get the “img_alt” field within the image content type. I was expecting to use

$row.imgAltText: $etImageSlotContentImage5getNode().getProperty(“rx:img_alt”).String

But can’t get the syntax right as it keeps throwing errors.

Any ideas?

Thanks

Chris

Chris,

Can you verify that your $row.imgAltText is missing the period between $etImageSlotContentImage5 and getNode() as shown in your pasted code.

Hi Riley,

Yes that’s a typo.

So, the bindings code for $row.imageAltText is:

$etImageSlotContentImage5.getNode().getProperty(“rx:img_alt”).String

I’ve double checked the ET_Image field name and it is img_alt

Question:
when you are doing the binding for the image, you are referring to the first object in the array ($etImageSlotContentImage5[0]) but when you get are trying to get the alt, you don’t? I haven’t used getSlotContents so I’m not sure on the exact syntax, but am just going by with what you have posted…

ie maybe the following assuming it isn’t null:
$etImageSlotContentImage5[0].getNode().getProperty(“rx:img_alt”).String

Brilliant! Thanks jitendra. This worked (and I’ve added a check on the slot contents)

if ($etImageSlotContentImage5 != ‘[]’){$etImageSlotContentImage5[0].getNode().getProperty(“rx:img_alt”).String;}else{0;}

I was pretty sure I had tried that and many other combinations but tried once more again and it now works.