FileTemplate["file"]
yields a TemplateObject expression that represents a file template to be applied using functions like TemplateApply.
FileTemplate[src]
uses File[…], URL[…], or CloudObject[…] as the specification for the file location.
FileTemplate[form,args]
yields a TemplateObject with arguments, suitable for cloud deployment or other evaluation.
FileTemplate
FileTemplate["file"]
yields a TemplateObject expression that represents a file template to be applied using functions like TemplateApply.
FileTemplate[src]
uses File[…], URL[…], or CloudObject[…] as the specification for the file location.
FileTemplate[form,args]
yields a TemplateObject with arguments, suitable for cloud deployment or other evaluation.
Details and Options
- FileTemplate will infer from the extension whether to interpret the contents as a StringTemplate, XMLTemplate, or NotebookTemplate.
- FileTemplate[CloudObject[…]] will infer the template type based on the contents of the cloud object.
- FileTemplate[File["path"]] and FileTemplate["path"] are effectively equivalent.
- The following special forms can be used in the file for FileTemplate:
-
`` TemplateSlot[] `n` TemplateSlot[n] `name` TemplateSlot["name"] <*expr*> TemplateExpression[expr] - FileTemplate has the following options:
-
CombinerFunction Automatic function to apply to combine pieces before returning a result InsertionFunction Automatic function to apply before inserting expressions Path $TemplatePath search for templates on the specified path
Examples
open all close allBasic Examples (1)
Loading a template file from disk:
t = FileTemplate["Examples/String/object.txt"]Applying to a FileTemplate:
TemplateApply[t, <| "object" -> "planet", "attribute" -> "big" |>]FileTemplateApply[t, <| "object" -> "planet", "attribute" -> "big" |>]The type of template to use is by default determined by the extension:
TemplateApply[
FileTemplate["Examples/XML/which.html"],
<|"data" -> {"Jupiter", "Earth", "Mars"}|>
]Scope (3)
File is fully supported:
FileTemplate[File["Examples/XML/sequence.html"]]Templates can be hosted in the Wolfram Cloud:
template = CloudDeploy[StringTemplate["hello i'm `Name`"]]FileTemplate[template]URL can be used to fetch templates:
template = URL @@ CloudExport["hi i'm `Name`", "String"]URLRead[template, "Body"]FileTemplate[template]URL can be directly used by TemplateApply:
TemplateApply[template, <|"Name" -> "john"|>]Options (2)
InsertionFunction (1)
Specify a function to convert arguments before they are inserted:
TemplateApply[
FileTemplate[
"Examples/XML/sequence.html",
InsertionFunction -> Composition[ToUpperCase, TextString]
],
<|"data" -> {"Jupiter", "Earth", "Mars"}|>
]TemplateApply[
FileTemplate[
"Examples/String/url.txt",
InsertionFunction -> URLEncode
],
<|"input" -> "Jupiter distance"|>
]You can use a string to specify an export format:
t = FileTemplate[
"Examples/String/object.txt",
InsertionFunction -> "JSON"
];
t[<|"object" -> {"list", "of", "data"}, "attribute" -> <|"json" -> "object"|>|>]Properties & Relations (2)
Evaluate $TemplatePath to see where FileTemplate is searching for templates:
$TemplatePathIf you deploy a template with data, each time you visit it TemplateApply will render the content again:
CloudDeploy[
FileTemplate[
File["Examples/XML/sequence.html"],
<|"data" :> {Now, RandomReal[], RandomReal[]}|>
]]See Also
History
Text
Wolfram Research (2014), FileTemplate, Wolfram Language function, https://reference.wolfram.com/language/ref/FileTemplate.html.
CMS
Wolfram Language. 2014. "FileTemplate." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/FileTemplate.html.
APA
Wolfram Language. (2014). FileTemplate. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/FileTemplate.html
BibTeX
@misc{reference.wolfram_2026_filetemplate, author="Wolfram Research", title="{FileTemplate}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/FileTemplate.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_filetemplate, organization={Wolfram Research}, title={FileTemplate}, year={2014}, url={https://reference.wolfram.com/language/ref/FileTemplate.html}, note=[Accessed: 13-June-2026]}