0

I send digest newsletters with the subscription module (using the templates that comes with the module), sometimes containing a small image before the teasertext (positioned with tables/row/column). This is all working well.

However in case there is no image available (because there is no teaser image uploaded to the applicable field or the contentitem doesn't even have a image field with that name) I get an ugly image outline in most email clients. I would like to test if there is an image available and if not, not adding the first ... leaving only the teaser text.

Can someone explain which "template" code must be used in order to achieve this?

Code used so far:

    Your subscriptions on [site:name] notify you of the following changes since the previous digest:<br />

    {{[subs:items:count]#<img src="http://@mydomain@/Newsletter/fine-line.jpg" width="580" height="18"><br />
    #1 of [subs:items:count] {{[subs:items:index:#0:subs:is-new]?(new):}}{{[subs:items:index:#0:subs:is-updated]?(updated):}}{{[subs:items:index:#0:subs:is-old]?(commented): <b>[subs:items:index:#0:as-node:title]</b>}}

    <table border="0" width="100%" padding="5">
        <tr>
            <td valign="top"><img src="[subs:items:index:#0:as-node:field_news_image]" alt="teaser image" width="100" /></td>
            <td style="font-family: Calibri, Arial, Helvetica, sans-serif;" valign="top" align="left">[subs:items:index:#0:as-node:summary]</td>
        </tr>
    </table> 
    Read more: [subs:items:index:#0:as-node:url]<br />
    }}
1
  • Added code in my question and removed it from the comments
    – Herbiek
    Sep 22 '14 at 7:39
0

If you can use php in the template (?) I would just wrap the cell containing the image in an if statement, something like this:

Your subscriptions on [site:name] notify you of the following changes since the previous digest:<br />

{{[subs:items:count]#<img src="http://@mydomain@/Newsletter/fine-line.jpg" width="580" height="18"><br />
#1 of [subs:items:count] {{[subs:items:index:#0:subs:is-new]?(new):}}{{[subs:items:index:#0:subs:is-updated]?(updated):}}{{[subs:items:index:#0:subs:is-old]?(commented): <b>[subs:items:index:#0:as-node:title]</b>}}

<table border="0" width="100%" padding="5">
    <tr>

        <?php if(**code to determine if image exists**): ?>
        <td valign="top"><img src="[subs:items:index:#0:as-node:field_news_image]" alt="teaser image" width="100" /></td>
        <?php endif ?>

        <td style="font-family: Calibri, Arial, Helvetica, sans-serif;" valign="top" align="left">[subs:items:index:#0:as-node:summary]</td>
    </tr>
</table> 
Read more: [subs:items:index:#0:as-node:url]<br />
}}

That way if there's no image it just won't print the cell at all and the other cell will take the entire width of the table.

If you can't use php in the template then I'm not sure how you could deal with it except perhaps by merging the two cells like this:

<td style="font-family: Calibri, Arial, Helvetica, sans-serif;" valign="top">
  <img src="[subs:items:index:#0:as-node:field_news_image]" alt="teaser image" width="100" />[subs:items:index:#0:as-node:summary]
</td>
2
  • I can't write php, so that would be not an option for me. I was hoping that the specific code used in template for subscriptions module would offer me such a if/else statement.
    – Herbiek
    Sep 22 '14 at 21:51
  • Then the edit just made is the only way I can think of to achieve your purpose beyond ensuring everything has an image.
    – Darvanen
    Sep 22 '14 at 23:29
0

Fixed it!

{{[subs:items:index:#0:as-node:field_news_image]==?:<td valign="top"><img src="[subs:items:index:#0:as-node:field_news_image]" width="100" /></td>}}

the part between ? and : is empty like the image I would test for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.