Hi team,
For FAQ CTAs, I’m trying to change the icon that display on the buttons conditionally based on the contents of their corresponding CTA labels.
Example:
- if my label contains a substring “read”, then I want a magnifying_glass icon.
- if my lab contains a substring “call”, then I want a phone icon.
I think I’m running into an issue where, because some of my FAQ entities do not have CTAs filled out, the code breaks because the iconName is passed an empty string based for FAQ entities with no CTA values based on the conditional statements in my code below (also attaching a screenshot in case the code is illegible here).
dataForRender(profile) {
var cta1 = ''
var cta2 = ''
if (profile.c_primaryCTA.label.includes("Read") == true) {
cta1 = 'receipt'; // The icon to use for the CTA
}
else if (profile.c_primaryCTA.label.includes("Call") == true){
cta1 = 'phone';
}
if (profile.c_secondaryCTA.label.includes("Read") == true) {
cta2 = 'magnifying_glass'; // The icon to use for the CTA
}
else if (profile.c_secondaryCTA.label.includes("Call") == true){
cta2 = 'person';
}
return {
title: profile.name, // The header text of the card
// subtitle: '', // The sub-header text of the card
details: profile.answer ? ANSWERS.formatRichText(profile.answer, "answer", "_top") : null, // The text in the body of the card
// If the card's details are longer than a certain character count, you can truncate the
// text. A toggle will be supplied that can show or hide the truncated text.
// showMoreDetails: {
// showMoreLimit: null, // Character count limit
// showMoreText: '', // Label when toggle will show truncated text
// showLessText: '' // Label when toggle will hide truncated text
// },
isExpanded: false, // Whether the accordion is expanded on page load
// The primary CTA of the card
CTA1: {
label: profile.c_primaryCTA ? profile.c_primaryCTA.label : null, // The CTA's label
iconName: cta1, // The icon to use for the CTA
url: Formatter.generateCTAFieldTypeLink(profile.c_primaryCTA), // The URL a user will be directed to when clicking
target: '_top', // Where the new URL will be opened. To open in a new tab use '_blank'
eventType: 'CTA_CLICK', // Type of Analytics event fired when clicking the CTA
// Event options for the analytics event fired when this CTA is clicked.
eventOptions: this.addDefaultEventOptions({ /* Add additional options here */ }),
// ariaLabel: profile.c_primaryCTA, // Accessible text providing a descriptive label for the CTA
},
// The secondary CTA of the card
CTA2: {
label: profile.c_secondaryCTA ? profile.c_secondaryCTA.label : null,
iconName: cta2, // The icon to use for the CTA
url: Formatter.generateCTAFieldTypeLink(profile.c_secondaryCTA),
target: '_top',
eventType: 'CTA_CLICK',
eventOptions: this.addDefaultEventOptions({ /* Add additional options here */ }),
// ariaLabel: profile.c_secondaryCTA,
},
};
Best,
Luc