Hi - I have 5 different snippets for different addresses that I need to use based on a website in my .csv datamapper. I wanted to use the snippets with a condition in the master page. DO I need to place each snippet in a separate div with just the article tag on the master page? I have tried a coupe different scenarios and can’t seem to get it to work properly. I have used an ID of #address that I have tried to place #address on each article tag and then again on each div. My script looks like this - I didnt think it would be difficult. I am sure I am just not placing something in the right place.
if (record.fields[“PARTLOGINSITE”].indexOf(“CSBANC.COM”)>= 0){
results.loadhtml(‘snippets/CSBaddress.html’);
} else{
if (record.fields[“PARTLOGINSITE”].indexOf(“BPAS.COM”)>= 0) {
results.loadhtml(‘snippets/BPASaddress.html’);
} else{
if (record.fields[“PARTLOGINSITE”].indexOf(“LOUISVILLETRUST.COM”)>= 0) {
results.loadhtml(‘snippets/LouisvilleAddress.html’);
} else{
if (record.fields[“PARTLOGINSITE”].indexOf(“MEMBERS.COM”)>= 0) {
results.loadhtml(‘snippets/MembersAddress.html’);
} else {
if (record.fields[“PARTLOGINSITE”].indexOf(“ROCKLANDTRUST.COM”)>= 0) {
results.loadhtml(‘snippets/RocklandAddress.html’);
}}}}}
When you’re chaining Else statements like that, you need to use Else If, like so:
if (condition1) { block of code to be executed if condition1 is true } else if (condition2) { block of code to be executed if the condition1 is false and condition2 is true } else { block of code to be executed if the condition1 is false and condition2 is false }
Note! The Snippets folder (Resources pane) lets group snippets in folders to organize these resources. The following coderefers to snippets in the address_blocks subfolder.
Note! From a performance perspective it is better to combine the address block information in a single snippet and wrap the individual blocks with a <div> having a unique ID. This reduces the number of content requests. The ID can be used as the second parameter in the loadhtml() command to retrieve the specific address from the snippet.