TransWikia.com

Building a Dynamic Table in Marketing Cloud

Salesforce Asked on August 17, 2020

I am trying to build a table within Marketing Cloud, where I have three rows and 2 columns.

For all records, there will be a value in both columns of the first row, however, for some this will be it, some will have values in the first and second row only, and others will have values in all rows.

I only want the row of the table to display when there are values.

Is this something that can be built using dynamic content blocks, or does it require AMPScript?

2 Answers

You don't need to use either. HTML will not render a row if there is no content in its cells. I think this may only apply where the table has 0 cellpadding and cellspacing. Try this:

<table border="1" cellspacing="0" cellpadding="0">
    <tr>
        <td>1. This row will be displayed.</td>
        <td></td>
    </tr>
    <tr>
        <td></td>
        <td>2. This row will be displayed.</td>
    </tr>
    </tr>
        <td><!-- 3. This row will not be displayed. --></td>
        <td></td>
    </tr>
    <tr>
        <td>4. This row will</td>
        <td>be displayed.</td>
    <tr>
</table>

enter image description here

Answered by Yosef Sahler on August 17, 2020

I'd go with AMPScript. Something like this:

%%[/* Modify to view AMPScript <div style="display:none"> */

var @r1c1, @r1c2, @r2c1, @r2c2, @r3c1, @r3c2
set @r1c1 = "r1c1"
set @r1c2 = "r1c2"
set @r2c1 = "r2c1"
set @r3c2 = "r3c2"
set @r3c1 = "r3c1"
set @r3c2 = "r3c2"

/*</div>*/
]%%
<table border="1">
    <tr>
        <td>%%=v(@r1c1)=%%</td>
        <td>%%=v(@r1c2)=%%</td>
    </tr>

    %%[ if not empty(@r2c1) or not empty(@r2c2) then ]%%
    <tr>
        <td>%%=v(@r2c1)=%%</td>
        <td>%%=v(@r2c2)=%%</td>
    </tr>
    %%[ endif ]%%    

    %%[ if not empty(@r3c1) or not empty(@r3c2) then ]%%
    <tr>
        <td>%%=v(@r3c1)=%%</td>
        <td>%%=v(@r3c2)=%%</td>
    </tr>
    %%[ endif ]%%  

</table>

Reference

Answered by Adam Spriggs on August 17, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP