Creating a Content Block for Fragments | Community
Skip to main content
Level 3
August 15, 2023
Question

Creating a Content Block for Fragments

  • August 15, 2023
  • 2 replies
  • 2045 views

Hey Everyone, 

 

I have a few footer fragments that have a phone number to call in for assistance. 

Well we have emails that need to have a cretan number associated to the type of email. I know you can't add dynamic content in a fragment but you can us content blocks. We use them to format a few things base off the data. But, what we are needing is it to look at the delivery label and set the number accordingly.

 

Example: 

Footer is for Account Alerts

  • One email is about a payment
  • One is about documents. 

Each one has the same footer but need to have a different number for the customer to call in. 

 

 

I know, I probably need to create separate fragments but there are a ton of emails to update if we go that route. This one we can create a content block and just update the handful of fragments and be done. 

 

Thanks for any help! 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

SatheeskannaK
Community Advisor
Community Advisor
August 15, 2023

@derekw42533281, Not sure if this helps. We do handle this at the content block level rather than fragments. We have a variable within the delivery template (example: var deltempId="1") to identify the footer to render from the content block. There will be only one content block containing all the different footers. Here is a snippet from the content block,

<!-- ########## Footer Type1 ########## -->
<% if (deltempId=="1") { %>All footer text<br />
<br /><% } %>

<!-- ########## Footer Type2 ########## -->
<% if (templateId=="2") { %>All footer text<br />
<br /><% } %>

Thanks, Sathees
Level 3
August 16, 2023

Thank you! 

 

I'll try this out and let you know if it worked or i have anymore questions.

Sukrity_Wadhwa
Community Manager
Community Manager
August 24, 2023

Hi @derekw42533281,

Did it work for you or do you still need help here? Let us know.

Thanks!

Sukrity Wadhwa
August 26, 2023

Hey there,

 

Ahmad here. I've faced similar issues in the past, especially when you're trying to maintain consistent branding across emails but with slight variations based on context.

 

You're right, fragments aren't designed for dynamic content. But content blocks, combined with scripting or conditional logic, might just do the trick.

 

Here's a potential solution using content blocks:

 

Create a Content Block: This content block will contain the scripting logic to look at the delivery label.

Scripting Logic: You can utilize platform-specific scripting (for example, AMPscript if you're using Salesforce Marketing Cloud) to read the delivery label.

Copy code

if deliveryLabel == 'payment' then
phoneNumber = '123-456-7890'
elseif deliveryLabel == 'documents' then
phoneNumber = '098-765-4321'
end if

 

Insert Content Block into Fragment: Now, instead of hardcoding the phone number in your footer fragment, you reference the content block. Whenever the email is compiled and sent, the content block should execute the script, check the delivery label, and populate the correct phone number.

Updating: If you ever need to change the logic or add new numbers, you just update the content block without touching the individual emails or fragments.

 

A couple of caveats:

 

Ensure that your platform supports using content blocks within fragments. While many do, some platforms have limitations.
Always test! Before rolling this out to all your emails, run a few test emails to ensure the logic works correctly, and the right phone number is displayed based on the delivery label.
It might sound a bit complex initially, but once set up, it'll save heaps of time in the long run, especially if you have many emails to manage.

Hope this helps! If anyone else has tried something different, I'd love to hear your approach. Cheers and good luck with your emails!