-
Notifications
You must be signed in to change notification settings - Fork 0
utility.Function.template
soetas edited this page Dec 1, 2024
·
2 revisions
estdlib v0.1.2 / utility / template
template(
templateString
,setting
?):void
Creates a compiled template function that can interpolate data properties in "interpolate" delimiters, HTML-escape interpolated data properties in "escape" delimiters, and execute JavaScript in "evaluate" delimiters
• templateString: string
The template string
• setting?: TemplateSetting
The options object
void
Returns the compiled template function
0.1.2
// Use the "interpolate" delimiter to create a compiled template
const compiled = template('hello <%= user %>!')
compiled({user:'fred'}) // => 'hello fred!'
// Use the HTML "escape" delimiter to escape data property values
const compiled = template('<b><%- value %></b>')
compiled({value:'<script>'}) // => '<b><script></b>'
// Use the "evaluate" delimiter to execute JavaScript and generate HTML
const compiled = template('<% users.forEach(function(user) { %><li><%- user %></li><% }) %>')
compiled({users:['fred', 'rose']}) // => '<li>fred</li><li>rose</li>'
Docs made with by typedoc、typedoc-plugin-markdown & typedoc-github-wiki-theme.