Skip to contents

Variables given as named arguments will override any variables in the environment with the same name.

Usage

template(msg, .name, ..., .envir = parent.frame())

Arguments

msg

A message object.

.name

A template name. This can be provided as either: (i) the name of a template that's baked into the package, (ii) a relative path or (iii) an absolute path. The paths must be for the directory containing the template files, not the files themselves.

...

Variables for substitution.

.envir

Environment for substitution.

Value

A message object.

Details

Will probably not get variables from environment if used as part of a pipeline. In this case might need to use the %|>% (nested pipe) operator.

Examples

# Use a builtin template.
envelope() %>%
  template(
    "newsletter",
    title = "A Sample Newsletter",
    articles = list(
      list(
        "title" = "Article (with date)",
        "content" = as.list("Vivamus, justo quisque, sed."),
        "date" = "1 January 2022"
      ),
      list(
        "title" = "Another Article (without date)",
        "content" = as.list("Quam lorem sed metus egestas.")
      )
    )
  )
# Use a custom local template.
if (FALSE) { # \dontrun{
envelope() %>%
  template("./templates/custom-template")
} # }