Loro Templates Documentation

Complete guide to template creation, testing, and API integration

1. Getting Started

1Register Your Account

Sign up at www.lorotemplates.com/login and confirm your email address.

2Get Your API Key

After email confirmation, you'll receive your API key via email. This key authenticates all your API requests.

Important: Keep your API key secure. Never expose it in client-side code or public repositories.

3Access the Dashboard

Login to access your dashboard where you can create, edit, and test templates.

2. Creating Templates

What are Scriban Templates?

Scriban is a powerful templating engine that allows you to generate dynamic content by combining templates with JSON data.

Template Syntax

Hello {{ name }}!

Your order details:
{{~ for item in items ~}}
- {{ item.name }}: ${{ item.price }}
{{~ end ~}}

Total: ${{ total }}

Creating Your First Template

  1. Go to your Dashboard
  2. Click "New Template"
  3. Fill in the template details:
    • Name: Descriptive name for your template
    • Description: What this template does
    • Category: Organize your templates
    • Content: Your Scriban template code
  4. Optionally add JSON Schema for validation
  5. Add sample JSON data for testing
  6. Click "Save Template"

Common Template Patterns

Variables

{{ variable_name }}
{{ user.first_name }}
{{ items[0].price }}

Conditionals

{{~ if user.premium ~}}
  Premium user benefits
{{~ else ~}}
  Standard features
{{~ end ~}}

Loops

{{~ for item in items ~}}
  {{ item.name }}
{{~ end ~}}

Functions

{{ date.now | date.to_string "%Y-%m-%d" }}
{{ name | string.upcase }}
{{ items | array.size }}

3. Testing Templates

Using the Template Tester

  1. From your dashboard, click "Test" on any template
  2. Enter your JSON data in the left panel
  3. See the rendered output in real-time on the right panel
  4. Iterate and refine your template until it's perfect

Sample JSON Data

{
  "name": "John Doe",
  "email": "john@example.com",
  "items": [
    {
      "name": "Widget A",
      "price": 29.99,
      "quantity": 2
    },
    {
      "name": "Widget B", 
      "price": 19.99,
      "quantity": 1
    }
  ],
  "total": 79.97,
  "date": "2024-01-15"
}

4. API Integration

Base URL

https://api.lorotemplates.com

Authentication

All API requests require your API key in the request header:

X-API-Key: your-api-key-here
Rate Limits: Free tier: 100 requests per month. Upgrade for higher limits.

5. Authentication

Every API request must include your API key in the X-API-Key header.

Example Request Headers

Content-Type: application/json
X-API-Key: your-api-key-here
Security Best Practices:
  • Never expose your API key in frontend JavaScript
  • Use environment variables to store your API key
  • Rotate your API key if compromised
  • Make API calls from your backend/server only

6. API Endpoints

POST/api/templates/render

Render a template with JSON data

Request Body

{
  "template_id": "uuid-of-template", // Optional: use saved template
  "template": "Hello {{ name }}!",   // Optional: inline template
  "data": {
    "name": "John Doe"
  }
}

Response

{
  "success": true,
  "result": "Hello John Doe!",
  "render_time_ms": 45
}

GET/api/templates

Get all your templates

Response

[
  {
    "id": "template-uuid",
    "name": "Welcome Email",
    "description": "Customer welcome email template",
    "category": "Emails",
    "is_active": true,
    "created_at": "2024-01-15T10:30:00Z",
    "updated_at": "2024-01-15T10:30:00Z"
  }
]

GET/api/templates/{id}

Get a specific template by ID

Response

{
  "id": "template-uuid",
  "name": "Welcome Email",
  "description": "Customer welcome email template", 
  "content": "Hello {{ customer.name }}!",
  "category": "Emails",
  "schema": "{ \"type\": \"object\" }",
  "sample_data": "{ \"customer\": { \"name\": \"John\" } }",
  "is_active": true,
  "created_at": "2024-01-15T10:30:00Z",
  "updated_at": "2024-01-15T10:30:00Z"
}

7. Code Examples

JavaScript / Node.js

const API_BASE = 'https://api.lorotemplates.com';
const API_KEY = process.env.LORO_API_KEY;

async function renderTemplate(templateData) {
  const response = await fetch(`${API_BASE}/api/templates/render`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-API-Key': API_KEY
    },
    body: JSON.stringify({
      template: 'Hello {{ name }}!',
      data: { name: 'John Doe' }
    })
  });
  
  const result = await response.json();
  console.log(result.result); // "Hello John Doe!"
}

Python

import requests
import os

API_BASE = 'https://api.lorotemplates.com'
API_KEY = os.getenv('LORO_API_KEY')

def render_template(template, data):
    response = requests.post(
        f'{API_BASE}/api/templates/render',
        headers={
            'Content-Type': 'application/json',
            'X-API-Key': API_KEY
        },
        json={
            'template': template,
            'data': data
        }
    )
    
    result = response.json()
    return result['result']

# Usage
output = render_template(
    'Hello {{ name }}!', 
    {'name': 'John Doe'}
)
print(output)  # "Hello John Doe!"

PHP

 $template,
        'data' => $data
    ]);
    
    $context = stream_context_create([
        'http' => [
            'method' => 'POST',
            'header' => "Content-Type: application/json\r\n" .
                       "X-API-Key: $apiKey\r\n",
            'content' => $postData
        ]
    ]);
    
    $response = file_get_contents("$apiBase/api/templates/render", false, $context);
    $result = json_decode($response, true);
    
    return $result['result'];
}

// Usage
$output = renderTemplate('Hello {{ name }}!', ['name' => 'John Doe']);
echo $output; // "Hello John Doe!"
?>

cURL

curl -X POST https://api.lorotemplates.com/api/templates/render \
  -H "Content-Type: application/json" \
  -H "X-API-Key: your-api-key-here" \
  -d '{
    "template": "Hello {{ name }}!",
    "data": {
      "name": "John Doe"
    }
  }'

8. Troubleshooting

Common Issues

401 Unauthorized

Cause: Missing or invalid API key

Solution: Ensure your API key is included in the X-API-Key header

400 Template Rendering Error

Cause: Syntax error in your template or invalid JSON data

Solution: Use the template tester to debug your template and data

429 Rate Limit Exceeded

Cause: You've exceeded your monthly API call limit

Solution: Upgrade your plan or wait until next month

404 Template Not Found

Cause: Invalid template ID

Solution: Verify the template ID exists in your dashboard

Getting Help

Need additional support?

Email us at admin@lorotemplates.com and we'll help you resolve any issues.

Made with care by the Loro Templates team

Go to Dashboard Login