Friday, August 9, 2013

My ExactTarget AMPscript skills come on a need-to-know basis. Learned a cool technique for styling dynamic tabular data.

It's not rocket science, and if this were JavaScript, PHP, etc. it would be a pretty easy thing, but AMPscript is proprietary and even though the documentation looks to be extensive, it never seems very easy to find what I'm looking for.

I first looked to create an array of values pulled from fields in the list, but I couldn't (relatively quickly) find the syntax for creating an array (not sure if it exists). For my purposes I needed to check about 10 different fields, so the code gets a little bloated, but not too bad. I should be looping through an array instead, but I digress.

I first check that the fields is not empty. I then have a nested condition that checks the value of a variable set for the background color of the table row. I toggle the background color every time, creating a nice readable banded table.

%%[ IF NOT EMPTY(@CLINIC_EXT_ID) THEN ]%%
  %%[ IF @rowColor == '#e1e1e1' THEN ]%%
  %%[ Set @rowColor = '#959595' ]%%
  %%[ ELSE ]%%
  %%[ Set @rowColor = '#e1e1e1' ]%%
  %%[ ENDIF ]%%
<tr style=”background-color:%%= v(@rowColor) =%%;”><td><strong>CLINIC EXT ID:</strong> </td><td>%%= v(@CLINIC_EXT_ID) =%%</td></tr>
%%[ ENDIF ]%%

No comments:

Post a Comment