Conditional Snippets in a Master page for address

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’);
}}}}}

Thank You

Amy

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
}

Thank you - that was an over sight on my part. I am all set on this now.

Thank you again.

Alternatively you could rename the snippets to the value you are comparing and use the value of the field in the loadhtml() command. E.g.

  • CSBANC.CO.html
  • ROCKLANDTRUST.COM.html
  • etc

The script code would look something like this:

results.loadhtml('snippets/' + record.fields["PARTLOGINSITE"] + '.html');

Erik

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.

results.loadhtml('snippets/address_blocks/' + record.fields["PARTLOGINSITE"] + '.html');

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.

Snippet:

<div id="CSBANC">CSBanc<br>Anywherestreet 1</div>
<div id="BPAS">BPAS<br>Rodeo drive 214</div>

Script:

results.loadhtml('snippets/address_blocks/addresses.html','#CSBANC');

See also: https://learn.objectiflune.com/en-us/planetpress-connect/howto/using-a-selector-to-load-part-of-a-snippet

Thank you very much !!! This really clarifies things for me.