2022.2

Table Of Contents
}
results.after(wpPost)
loadtext()
Loadstextfromthespecifiedtextfile,forexampleaJavaScriptfile(.js)orstylesheet(.css).
ThetextfilemaybelocatedinsidethetemplateorhostedonaContentManagementSystemoron
anotherlocationoutsidethetemplate.
Tip: ToloadanHTMLfragment,youcanuseuseloadhtml()(see"loadhtml()LoadsHTML
contentfromthespecifiedHTMLfile.Thefilemaybelocatedinsidethetemplate(see"Snippets"
onpage1)orhostedonaContentManagementSystemoronanotherlocationoutsidethetem-
plate.Anoptionalselectorallowsyoutoretrieveonlythecontentofmatchingelements.Thespe-
cifiedHTMLfileisexpectedtobeUTF-8encoded.Loadhtml()iscachedperbatchrun(basedon
theURL)inprint/email.ToloadaJavaScriptfile(.js)orastylesheet(.css)youcanuseloadtext().
See"loadtext()"onpage1.Externalcontentisnotloadedwhileeditingascript.Totestascript
thatloadsexternalcontent,youcandoapreflight;see"DoingaPreflight"onpage1.loadhtml(loc-
ation)LoadsallHTMLfromthespecifiedHTMLfile.locationStringcontainingapaththatcanbe
absoluteorrelativetothesection/context.Usesnippets/<snippet-name>toretrievethecontent
fromanHTMLfileresidingintheSnippetsfolderontheResourcespanel.Inordertoretrievefiles
fromoutsidethetemplatethefileprotocolissupportedaswellasthehttp/httpsprotocols.The
completesyntaxofafullyqualifiedURLwiththe"file"protocolis:file://<host>/<path>.Ifthehost
is"localhost",itcanbeomitted,resultinginfile:///<path>,forexample:file:///c:/-
somefolder/somecontent.html.Whenusingthehttp/httpsprotocol,rememberthatonlyabsolute
pathsaresupportedinsideremotesnippets(see"Remotesnippets"onpage1).Toquicklyget
thelocationofanHTMLsnippetinthetemplateresources,right-clickthesnippetinthe
ResourcespaneandselectCopyResourceLocation.ThepathtoaremoteHTMLsnippetcanbe
copiedfromthesnippet'sproperties:right-clickthesnippetintheResourcespaneandselect
Properties.ExamplesThisscriptloadsalocalHTMLsnippet(fromtheResourcespanel)directly
intothematchedelementsresults.loadhtml("snippets/snippet.html");Thefollowingscriptloadsa
localHTMLsnippet(Resourcespanel)intoavariable.ThereplaceWith()commandisusedto
replacetheelement(s)matchedbythescript'sselectorwiththecontentsofthesnippet.varmys-
nippet=loadhtml('snippets/snippet.html');results.replaceWith(mysnippet);Sameresultasthe
previousscript,butadifferentnotation:results.replaceWith(loadhtml('snip-
pets/snippet.html'));Thefollowingscriptloadsasnippetintoavariableandfinds/replacestextin
thevariablebeforeinsertingthecontentintothepage.Thesecondfindcommandalsoadds
formattingtothereplacingtext.varmysnippet=loadhtml
('file:///C:/Users/PParker/Documents/Example.html');mysnippet.find('@var1@').text('OLCon-
nect1');mysnippet.find('@var2@').html('<i>OLConnect2</i>').css('text-
Page 730