Skip to content
Browse all functions

Create Text / HTML from Template and Data

data/template2text

template2text (Create Text / HTML from Template and Data) is a 1001fx API function in the group Data & JSON: POST https://api.1001fx.com/data/template2text, 2 credits per call. It works as a ready-made module in Make and n8n or as a plain HTTP call.

2 credits per callHTTP APIn8nMake

Creates any text from template and given data. For example, dynamically generate HTML templates with data and logic, making it useful for building dynamic web applications. Based on Handlebars - see https://handlebarsjs.com/ for more details.

Try it in the 1001fx app

Run template2text in your browser with your API key – fill the form, click Run and get the answer or the file.

template2text in the 1001fx app: the form with example values
Create Text / HTML from Template and Data in the 1001fx app

Endpoint

POSThttps://api.1001fx.com/data/template2text
Header
X-API-KEY: YOURSECRETAPIKEY How to
Content type
application/json

Parameters

  • templatestringrequired

    Template to be filled in with data. For expressions you can use the following syntaxes: {{ name }} and { { name } }. See handlebars documentation.

    Example:
    "{{#each peopleData}}<div class='person'><h2>{{name}}</h2><p><strong>Age:</strong> {{age}}</p><p><strong>Occupation:</strong> {{occupation}}</p><p><strong>Email:</strong> {{email}}</p></div>{{/each}}"
  • dataobjectoptional

    Data used to fill the template.

  • dataStringstringoptional

    Stringified Data used to fill the template.

    Example:
    {"peopleData":[{"name":"John Smith","age":32,"occupation":"Software Engineer","email":"john.smith@example.com"},{"name":"Jane Doe","age":27,"occupation":"Marketing Manager","email":"jane.doe@example.com"}]}
  • noEscapebooleanoptional

    Set to true to not HTML escape any content.

    Example:
    false
  • preventIndentationbooleanoptional

    By default, an indented partial-call causes the output of the whole partial being indented by the same amount. This can lead to unexpected behavior when the partial writes pre-tags. Setting this option to true will disable the auto-indent feature.

    Example:
    true

Examples

Data as JSON object

Renders a Handlebars template with the object in data.

Input

Expects a json body
{
  "template": "{{#each peopleData}}<div class='person'><h2>{{name}}</h2><p><strong>Age:</strong> {{age}}</p><p><strong>Occupation:</strong> {{occupation}}</p><p><strong>Email:</strong> {{email}}</p></div>{{/each}}",
  "data": {
    "peopleData": [
      {
        "name": "John Smith",
        "age": 32,
        "occupation": "Software Engineer",
        "email": "john.smith@example.com"
      },
      {
        "name": "Jane Doe",
        "age": 27,
        "occupation": "Marketing Manager",
        "email": "jane.doe@example.com"
      }
    ]
  },
  "noEscape": false,
  "preventIndentation": true
}

Output · HTTP 200

Response
{
  "result": "<div class='person'><h2>John Smith</h2><p><strong>Age:</strong> 32</p><p><strong>Occupation:</strong> Software Engineer</p><p><strong>Email:</strong> john.smith@example.com</p></div><div class='person'><h2>Jane Doe</h2><p><strong>Age:</strong> 27</p><p><strong>Occupation:</strong> Marketing Manager</p><p><strong>Email:</strong> jane.doe@example.com</p></div>"
}
Show curl command
curl -X POST 'https://api.1001fx.com/data/template2text' \
  -H 'X-API-KEY: YOURSECRETAPIKEY' \
  -H 'Content-Type: application/json' \
  -d '{"template":"{{#each peopleData}}<div class='\''person'\''><h2>{{name}}</h2><p><strong>Age:</strong> {{age}}</p><p><strong>Occupation:</strong> {{occupation}}</p><p><strong>Email:</strong> {{email}}</p></div>{{/each}}","data":{"peopleData":[{"name":"John Smith","age":32,"occupation":"Software Engineer","email":"john.smith@example.com"},{"name":"Jane Doe","age":27,"occupation":"Marketing Manager","email":"jane.doe@example.com"}]},"noEscape":false,"preventIndentation":true}'

Data as JSON string

Renders the same template with the data passed as dataString.

Input

Expects a json body
{
  "template": "{{#each peopleData}}<div class='person'><h2>{{name}}</h2><p><strong>Age:</strong> {{age}}</p><p><strong>Occupation:</strong> {{occupation}}</p><p><strong>Email:</strong> {{email}}</p></div>{{/each}}",
  "dataString": "{\"peopleData\":[{\"name\":\"John Smith\",\"age\":32,\"occupation\":\"Software Engineer\",\"email\":\"john.smith@example.com\"},{\"name\":\"Jane Doe\",\"age\":27,\"occupation\":\"Marketing Manager\",\"email\":\"jane.doe@example.com\"}]}"
}

Output · HTTP 200

Response
{
  "result": "<div class='person'><h2>John Smith</h2><p><strong>Age:</strong> 32</p><p><strong>Occupation:</strong> Software Engineer</p><p><strong>Email:</strong> john.smith@example.com</p></div><div class='person'><h2>Jane Doe</h2><p><strong>Age:</strong> 27</p><p><strong>Occupation:</strong> Marketing Manager</p><p><strong>Email:</strong> jane.doe@example.com</p></div>"
}
Show curl command
curl -X POST 'https://api.1001fx.com/data/template2text' \
  -H 'X-API-KEY: YOURSECRETAPIKEY' \
  -H 'Content-Type: application/json' \
  -d '{"template":"{{#each peopleData}}<div class='\''person'\''><h2>{{name}}</h2><p><strong>Age:</strong> {{age}}</p><p><strong>Occupation:</strong> {{occupation}}</p><p><strong>Email:</strong> {{email}}</p></div>{{/each}}","dataString":"{\"peopleData\":[{\"name\":\"John Smith\",\"age\":32,\"occupation\":\"Software Engineer\",\"email\":\"john.smith@example.com\"},{\"name\":\"Jane Doe\",\"age\":27,\"occupation\":\"Marketing Manager\",\"email\":\"jane.doe@example.com\"}]}"}'

Try template2text now

Run it in your browser or create a free account and get 100 credits every month.

Changelog

  • 1.0.004.04.2023created
Ask 1001fx