2022.2

Table Of Contents
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"onpage661).
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.
Step1:Gettingtheappropriatelink
Torequestcontentfromanotherserver,youwillneedalink.
Somewebsitesgivetheoptiontoembedtheircontentinyourwebsitebyprovidingalinkorthecom-
pleteHTML.Youtube.com,forexample,offersnotonlyalinktoshareacertainvideo,butalsothefull
HTMLtoembedthatvideoinyourwebsite.
Ifthatoptionisnotavailable,youwillhavetobuildthelinkyourself.Findtheserver'sAPIandlook
throughittogettheexactendpointandparametersthatyouneed.
WithmanyserversitisrequiredtouseanAPI keyinthelink;thiskeygenerallycomesforfreeafteryou
signuptotheirwebsite.Thekeywillbepartofthelinkthatisusedtomakearequesttotheserver.
Note: Payattentiontotheservice'sTermsofService.Manyservershavelimitationsonthenum-
berofcallsthatcanbemadetothemforfree.Beyondtheselimits,theircontentwillnotshowup
inyourtemplateunlessyoupurchaseabusinessplan.
Step2:Preparingthetemplate
Thenextstepistosetupatemplate.Ifyou'vegottheHTMLtoembedcontentinyourtemplateyoucan
pastethatHTMLontheSourcetab(andskipStep3).
Otherwiseyourtemplatehastocontainanelementthatcanbereplacedorfollowedbytheremotecon-
tent:anemptyparagraph,forexample,oraheading.Iftheelementisn'tuniqueinthetemplate,give
theelementanID.
Notethatinteractivecontent,suchasaninteractivemap,canonlybeusedinWebtemplates,andcan-
notbeoutputonPrintorEmailcontexts(eventhoughtheywillshowupinPreviewmode!).
Step3:Writingascript
Thefinalstepistowriteascriptthatretrievesthecontentandinsertsitintothetemplate(see"Writing
yourownscripts"onpage808).UsetheelementortheIDoftheelementthatyouaddedinStep2as
thescript'sselector.Forinformationaboutselectors,see"SelectorsinOLConnect"onpage825.
Page 833