2022.2

Table Of Contents
Withasnippetondisk,thecompletesyntaxis:file://<host>/<path>.Ifthehostis"localhost",itcanbe
omitted,resultinginfile:///<path>-notethethreeforwardslashesafterfile:.
Intheremainderofthepathyoucaneitheruseescapedbackwardslashes:
"file:///C:\\Users\\Administrator\\Desktop\\Handlebars_LoadFile.hbs"
orforwardslashes:
"file:///C:/Users/Administrator/Desktop/Handlebars_LoadFile.hbs"
Note: Apartialiscompiledautomaticallywhenthetemplateinwhichitisinsertedisrendered.
Using a registered partial in a template
Registeredpartials(see"Howtoregisterapartial"onthepreviouspage)canbereferredtobyname
insteadoffilename,usingthefollowingsyntax:
{{> partialName}}.
Forexample,apartialthatisregisteredasfollows:
Handlebars.registerPartial('clauses', 'snippets/partials/clauses.hbs');
canbeincludedinaHandlebarstemplatewiththefollowingexpression:{{>clauses}}.
When a partial is missing
Ifthereisnopartialwiththespecifiedname,Handlebarscangeneratesomeothercontent,calledfail-
over content.Failovercontentcanbespecifiedusingblocksyntax.Theexpressionthatcallsthepar-
tialisthestartofablock.Anexpressionwithaclosingtagandthenameofthepartialsignalstheendof
theblock.Thecontentbetweentheseexpressionswillbeusedifthecalledpartialismissing.
Forexample:{{#>myPartial}}Failovercontent{{/myPartial}}willrender"Failovercontent"ifthe
"myPartial"partialisnotregistered.
Dynamic partials
Toloadpartialsdynamically,basedondata,youcoulduseablockhelper(see"Usingfunctionsin
expressions:Helpers"onpage766and"UsingHandlebarstemplates:examples"onpage777).
Itisalsopossibletodynamicallyselectapartialbyusingasub expressionbetweenparentheses.The
subexpressionshouldevaluatetothenameofapartial.
Forexample,ifwhichPartialisafunctionthatreturnsthenameofapartial,{{> (whichPartial)
}}inaHandlebarstemplatecallswhichPartialandthenrendersthepartialwhosenameisreturned
bythisfunction.
Notethattouseafunctioninthisway,itmustberegisteredasaHelper.See"CreatingcustomHelp-
ers"onpage771.
Page 779