I'm working on a platform in which we send personalized email campaigns.
Each campaign is based on one email template (SendGrid Design) which we dynamically generate to contain all the possible content blocks.
Then we use Handlebars to show the content blocks just for the contacts that match certain criteria.
Example:
<h1>This is the mail</h1>
{{or user_branch_finance user_branch_technology}}
<p>This is content for Finance and Technology contacts</p>
{{/or}}
{{or user_branch_government user_branch_health}}
<p>This is content for Government and Health contacts</p>
{{/or}}
That principle works if each content block is related to just one or two properties (using {{if}}
for one and {{or}}
for two properties) but it seems that {{or}}
is limited to only 2 parameters leaving us with the challenge of dealing with content blocks that are meant for more properties.
In our case, we potentially have content blocks that are related to 10 or more properties.
What I tried so far:
// Approach 1
// fails (always false):
{{or prop1 prop2 prop3 prop4}}
// Approach 2
// fails (template invalid):
{{or prop1 prop2}}
content here
{{else or prop3 prop4}}
repeat same content here
{{/or}}
// Approach 3
// fails (template invalid):
{{or prop1 prop2}}
content here
{{else or prop3 prop4}}
repeat same content here
{{/or}}
// Approach 4
// fails (template invalid):
{{or prop1 prop2}}
content here
{{else}}
{{or prop3 prop4}}
repeat same content here
{{/or}}
{{/or}}
The only thing that works is this:
// Approach 5
// works (but suboptimal):
{{if prop1}}
content here
{{else if prop2}}
repeat same content here
{{else if prop3}}
repeat same content here
{{else if prop4}}
repeat same content here
{{/or}}
While that works, it is not preferred because I need to repeat the same content many times within the same design. That wouldn't be an issue were it not for a 1MB limit on the template (at least when created through the API).
My question is if anyone sees a better solution. Preferably one in which I only have to define my content block once.