FileTemplateApply[template]
applies a template, evaluating all template elements it contains, and then writes the result to a temporary file, whose name is returned.
FileTemplateApply[template,args]
applies a template, using args to fill its slots, and then writes the result to a temporary file.
FileTemplateApply[template,output]
applies a template, writing the results to the file represented by output.
FileTemplateApply[template,args,output]
applies a template, using args to fill its slots, and then writes the result to the file represented by output.
FileTemplateApply
FileTemplateApply[template]
applies a template, evaluating all template elements it contains, and then writes the result to a temporary file, whose name is returned.
FileTemplateApply[template,args]
applies a template, using args to fill its slots, and then writes the result to a temporary file.
FileTemplateApply[template,output]
applies a template, writing the results to the file represented by output.
FileTemplateApply[template,args,output]
applies a template, using args to fill its slots, and then writes the result to the file represented by output.
Details and Options
- FileTemplateApply operates on template and args just like TemplateApply.
- By default, FileTemplateApply will overwrite any existing content in output if it can.
- The output file can be specified as File["file"] or "file".
- FileTemplateApply takes the following options:
-
CombinerFunction Inherited function to apply to combine pieces before returning a result InsertionFunction Inherited function to apply before inserting expressions
Examples
open all close allBasic Examples (1)
FileTemplateApply works with any expression:
FileTemplateApply[{"template", TemplateObject["content"]}]The first argument is handled by TemplateApply and can be a String, File, or any TemplateObject:
FileTemplateApply[
"This planet is `planet`",
<|"planet" -> "Jupiter"|>
]FileTemplateApply[
TemplateObject[{"This planet is ", TemplateSlot["planet"]}, CombinerFunction -> StringJoin],
<|"planet" -> "Jupiter"|>
]Specify a path to export the template in the specified location:
FileTemplateApply[
"This planet is `planet`",
<|"planet" -> "Jupiter"|>,
"template.html"
]Scope (5)
File is fully supported:
result = FileTemplateApply[
File["Examples/XML/sequence.html"],
<|"data" -> {1, 2, 3}|>
]Import[result]File can also be used as a third argument, to specify the result:
FileTemplateApply[
File["Examples/XML/sequence.html"],
<|"data" -> {1, 2, 3}|>,
File["result.txt"]
]Templates can be hosted in the Wolfram Cloud:
template = CloudDeploy[StringTemplate["hello i'm `Name`"]]result = FileTemplateApply[
template,
<|"Name" -> "John"|>,
File["result.txt"]
]Import[result]The result can be saved to a CloudObject:
template = CloudDeploy[StringTemplate["hello i'm `Name`"]]result = FileTemplateApply[template, <|"Name" -> "John"|>, CloudObject[]]Import[result]URL can be used to fetch templates:
template = URL@@CloudExport["hi i'm `Name`", "String"]URLRead[template, "Body"]FileTemplateApply[
template,
<|"Name" -> "John"|>,
File["result.txt"]
]See Also
Related Guides
History
Text
Wolfram Research (2014), FileTemplateApply, Wolfram Language function, https://reference.wolfram.com/language/ref/FileTemplateApply.html.
CMS
Wolfram Language. 2014. "FileTemplateApply." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/FileTemplateApply.html.
APA
Wolfram Language. (2014). FileTemplateApply. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/FileTemplateApply.html
BibTeX
@misc{reference.wolfram_2026_filetemplateapply, author="Wolfram Research", title="{FileTemplateApply}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/FileTemplateApply.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_filetemplateapply, organization={Wolfram Research}, title={FileTemplateApply}, year={2014}, url={https://reference.wolfram.com/language/ref/FileTemplateApply.html}, note=[Accessed: 12-June-2026]}