2022.2

Table Of Contents
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368).UsetheelementortheIDoftheelementthatyouaddedinStep2as
thescript'sselector.Forinformationaboutselectors,see"SelectorsinOLConnect"onpage385.
Tip: Selectanelement,thenclickon'ID'intheAttributespane,tocreateascriptthathasthatele-
ment'sIDasselector.
Retrieving content
Dependingonthetypeofcontentthattheremoteserverreturns-HTMLorJSON-youcanuseload-
html(location)orloadjson(location)(seealso:"loadhtml()"onpage726and"loadjson()"on
page729)toretrievethecontent.ThelinkthatyouselectedinStep1shouldbepassedtothefunction
asastring.Forexample:
loadjson('https://blog.mozilla.org/wp-json/wp/v2/posts?per_page=5');
Page 393