0

I know how to embed an image into a template. See this question. My question is how to do it in a loop:

<table>
     #foreach( $object in $objects )
        <tr>
            <td>
                <img src="cid:${image_cid}"/>
            </td>
...

The problem is I need to create a dynamic unique cid placeholder, e.g.:

<img src="cid:${object1_image_cid}"/>
....
<img src="cid:${object2_image_cid}"/>

I've tried using a variable inside of the ${image_cid} variable, but that just crashes. e.g. I tried

${$object.id image_cid}

Any suggestions or ways to solve this?

Community
  • 1
  • 1
Brian Kates
  • 480
  • 4
  • 14

1 Answers1

0

Thanks to Ismail for this suggestions. Here's what I did. In my Java code, I set all of the cids in a transient field on the object, e.g.:

for ( Object object : objects ) {
        String artworkCid = email.embed(file);
        object.setCid(artworkCid);
}

Then, in the template:

#foreach( $object in $objects )
      <tr>
            <td>
                <img src="cid:$object.cid" />

(obfuscated everything to object)

Brian Kates
  • 480
  • 4
  • 14