2022.2

Table Of Contents
Example: ThefollowingscriptevaluatesifthevalueoftheLANGUAGEfieldintherecordis‘En’.
Ifso,thesnippetisaddedtothecontent.
if (record.fields.LANGUAGE == ‘En’) {
results.loadhtml(‘snippets/nameofthesnippet.html’);
}
Anotherexampleisgiveninahow-to;seeLoadasnippetbasedonadatafieldvalue.
Loadingpartofasnippet,basedonthevalueofadatafield
Whenasnippetcontainsapartthatcanbeidentifiedbyaselector,thatselectorcanbeusedtoload
thatpartofthesnippetintoatemplate.Itispossibletodothis,basedonthevalueofthedatafield.This
iseasiestwhentheselectormatchesthevalueofadatafield.
Example: ThefollowingscriptreadsthevalueoftheLANGUAGEfieldintherecordanduses
thatvalueastheselectorinthefunctionloadhtml().IfthesnippetcontainsanHTMLelementwith
thisID(forexample,<pID=”En”>),thatHTMLelementwillbeaddedtothecontent:
var language = record.fields.LANGUAGE;
results.loadhtml(‘snippets/nameofthesnippet.html’,#’+ language)
Anotherexampleisgiveninthefollowinghow-to:Usingaselectortoloadpartofasnippet.
Seealso:"StandardScriptAPI"onpage1169.
Tip:
AneasywaytogroupcontentinanHTMLsnippetisputtingeachpartinacontainerandgiving
thatcontaineranID,forexample:
<divID=”EN”><p>ThisistextforEnglishcustomers.</p></div>
Usethefunction.children()toloadthecontentsofthecontainer,andnotthecontainer
itself.Forexample:
results.loadhtml(‘Snippets/myfooter.html’,#EN’).children()
Thisscriptloadstheparagraphoftheexample(<p>),butnotthecontaineritself(<div>).
Loadasnippetandinsertvariabledataintoit
ThefollowingscriptloadspartofanHTMLsnippetbasedonthevalueofafield,andthenfind-
s/replacestextwiththevalueofafieldbeforeinsertingthecontentintothedocument.
var promoTxt = loadhtml('snippets/promo-en.html', '#' + record.fields['YOGA']);
Page 832