2022.2

Table Of Contents
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715.
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']);
promoTxt.find('@first@').text(record.fields['FIRSTNAME']);
results.html(promoTxt);
Loading content using a server's API
Contentinatemplateisusuallystatic(apartfrombeingpersonalized)andpartofthemaintextflow.It
canalsobelocatedinasnippet(see"Snippets"onpage250).
Itisalsopossibletoincludecontentthatisservedbyanotherserver.ManyserversprovideanAPIto
fetchpubliclyavailablecontentfromtheirsite.Thatcontentmayevenbedynamic:themost recent
blogpostsonaWordpresswebsite,forexample,orthecurrentweatherforecastforacertaincity.
Thistopicexplainshowtoretrievecontentusingaserver'sAPIandinsertthatcontentinatemplate.
Page 392