Debian Codegraph @

man/render.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/render.R
3 \name{render}
4 \alias{render}
5 \alias{render.character}
6 \alias{render.fs_path}
7 \alias{render.jinjar_template}
8 \title{Render a template}
9 \usage{
10 render(.x, ...)
11
12 \method{render}{character}(.x, ..., .config = default_config())
13
14 \method{render}{fs_path}(.x, ..., .config = default_config())
15
16 \method{render}{jinjar_template}(.x, ...)
17 }
18 \arguments{
19 \item{.x}{The template. Choices:
20 \itemize{
21 \item A template string.
22 \item A path to a template file (use \code{\link[fs:path]{fs::path()}}).
23 \item A parsed template (use \code{\link[=parse_template]{parse_template()}}).
24 }}
25
26 \item{...}{<\code{\link[rlang:dyn-dots]{dynamic-dots}}> Data passed to the template.
27
28 By default, a length-1 vector is passed as a scalar variable. Use \code{\link[=I]{I()}} to
29 declare that a vector should be passed as an array variable. This preserves
30 a length-1 vector as an array.}
31
32 \item{.config}{The engine configuration. The default matches Jinja defaults,
33 but you can use \code{\link[=jinjar_config]{jinjar_config()}} to customize things like syntax delimiters,
34 whitespace control, and loading auxiliary templates.}
35 }
36 \value{
37 String containing rendered template.
38 }
39 \description{
40 Data is passed to a template to render the final document.
41 }
42 \examples{
43 # pass data as arguments
44 render("Hello {{ name }}!", name = "world")
45
46 # pass length-1 vector as array
47 render("Hello {{ name.0 }}!", name = I("world"))
48
49 # pass data programmatically
50 params <- list(name = "world")
51 render("Hello {{ name }}!", !!!params)
52
53 # render template file
54 \dontrun{
55 render(fs::path("template.txt"), name = "world")
56 }
57 }
58 \seealso{
59 \itemize{
60 \item \code{\link[=parse_template]{parse_template()}} supports parsing a template once and rendering multiple
61 times with different data variables.
62 \item \code{vignette("template-syntax")} describes how to write templates.
63 }
64 }