interpolate: Interpolate variables in a file

Description Usage Arguments Details Value Examples

Description

This function reads the contents of a file and performs a search-and-replace on a set of given variable names with given values. In the context of a CGI script, this function is useful for interpolating HTML templates and using them as the HTTP response. variable occurrences are marked with a sentinel character, which defaults to "%".

Usage

1
interpolate(filename, values, sentinel = "%")

Arguments

filename

the name of the file containing the text to be interpolated

values

a named vector, in which the names are used as the variable names, and the values as the variable values.

sentinel

a sentinel character indicating a variable in the text. Defaults to "%".

Details

For example, given the text "Hello %foo" and the variable foo="World", the interpolation will produce the text "Hello World"

Value

the interpolated text.

Examples

1
2
3
error <- "Insufficient amount of coffee!"
errorHTML <- interpolate("../../html/app/error.html",c(message=error))
respondHTML(errorHTML)

jweile/cgir documentation built on May 10, 2019, 10:02 a.m.