html
Overview
Section titled “Overview”The html
function in Regor is a utility function for creating HTML strings using template literals and interpolating values into the resulting string. It is commonly used to generate HTML content dynamically within Regor components.
Creating HTML Strings
Section titled “Creating HTML Strings”The html
function takes two parameters:
-
templates
(TemplateStringsArray): An array of string literals representing the static parts of the HTML template. -
...args
(any[]): Any number of additional arguments that will be interpolated into the template to generate the dynamic parts of the HTML.
Example
Section titled “Example”import { html } from 'regor'
// Create an HTML string with dynamic contentconst name = 'John'const age = 30const htmlString = html`<p> Hello, my name is ${name} and I am ${age} years old.</p>`
// The resulting HTML string:// "<p>Hello, my name is John and I am 30 years old.</p>"
Parameters
Section titled “Parameters”-
templates
(TemplateStringsArray): An array of string literals representing the static parts of the HTML template. -
...args
(any[]): Any number of additional arguments that will be interpolated into the template to generate the dynamic parts of the HTML.
Return Value
Section titled “Return Value”- Returns a string that represents the HTML content generated by interpolating the template literals and values provided in the
args
array.
-
The
html
function is useful for creating HTML strings with dynamic content, such as when generating HTML markup for Regor components or templates. -
It uses JavaScript’s template literal syntax to define the static parts of the HTML template and interpolates values into the template using
${...}
placeholders. -
The resulting HTML string can be directly used in your Regor components or inserted into the DOM as needed.
-
In Regor, this function is commonly used in conjunction with template rendering and component creation to generate HTML content.