Skip to content

raw

The raw function in Regor is an alias for the html function. It serves the same purpose and can be used interchangeably with html to create HTML strings from template literals and interpolated values. It is commonly used to generate HTML content dynamically within Regor components.

The raw function is essentially identical to the html function, and its usage is the same. It allows you to create HTML strings with dynamic content using template literals and interpolating values into the resulting string.

import { raw } from 'regor'
// Create an HTML string with dynamic content
const name = 'John'
const age = 30
const htmlString = raw`<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>"
  • 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.

  • Returns a string that represents the HTML content generated by interpolating the template literals and values provided in the args array.
  • The raw function is functionally equivalent to the html function and can be used interchangeably. It provides a convenient way to create HTML strings with dynamic content.

  • Like the html function, 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.

Back to the API list