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. VS Code Extension

Loro Templates VS Code Extension

The official VS Code extension provides syntax highlighting, IntelliSense, and debugging support for Scriban templates directly in your editor.

Installation

Option 1: VS Code Marketplace

  1. Open VS Code
  2. Go to Extensions (Ctrl+Shift+X)
  3. Search for "Loro Templates" or "Scriban"
  4. Click Install on the official extension

Option 2: Command Line Installation

code --install-extension lorotemplates.loro-templates

Features

Syntax Highlighting

Full syntax highlighting for .scriban files with proper color coding for variables, functions, and control structures.

IntelliSense

Auto-completion for Scriban functions, variables, and built-in objects like date, string, math, and array functions.

Error Detection

Real-time syntax error detection and validation with helpful error messages and suggestions.

Template Testing

Test templates directly in VS Code with sample JSON data and see rendered output instantly.

Usage

Creating a Template

  1. Create a new file with .scriban extension
  2. Start typing your template - you'll get syntax highlighting automatically
  3. Use Ctrl+Space for IntelliSense suggestions
  4. Save and test your template

Testing Templates

  1. Open Command Palette (Ctrl+Shift+P)
  2. Type "Loro: Test Template"
  3. Provide sample JSON data when prompted
  4. View rendered output in a new tab

Configuration

Configure the extension through VS Code settings:

{
  "loro.apiKey": "your-api-key-here",
  "loro.apiUrl": "https://api.lorotemplates.com",
  "loro.autoValidate": true,
  "loro.showInlineErrors": true
}

Security Note: Store your API key securely using VS Code's built-in secrets management or environment variables.

9. CLI Package

Loro CLI

The command-line interface allows you to transform templates, manage configurations, and integrate Loro Templates into your build processes and automation workflows.

Installation

Install via NPM

npm install -g @lorotemplates/cli

Verify Installation

loro --version

Configuration

Configure your API credentials before using the CLI:

# Interactive configuration
loro config

# Set API key directly
loro config --api-key YOUR_API_KEY

# Set API URL (if using custom endpoint)
loro config --api-url https://api.lorotemplates.com

# View current configuration
loro config --list

Commands

loro remote<guid> -d data.json

Transform using a remote template by GUID

# Basic usage
loro remote 72d561bf-3c17-4b34-b48d-cee00f1f0e1e -d data.json

# Save to file
loro remote 72d561bf-3c17-4b34-b48d-cee00f1f0e1e -d data.json -o output.txt

# Show template before transformation
loro remote 72d561bf-3c17-4b34-b48d-cee00f1f0e1e -d data.json --show-template

# Verbose output
loro remote 72d561bf-3c17-4b34-b48d-cee00f1f0e1e -d data.json --verbose

loro list

List all available templates

# List templates
loro list

# Search templates
loro list -s "invoice"

# Show more results
loro list -l 20

# Output as JSON
loro list --json

loro stats

Show usage statistics and account information

# View usage stats
loro stats

# Detailed statistics
loro stats --verbose

# Output as JSON
loro stats --json

loro transform

Transform local templates or use remote templates

# Transform local template
loro transform template.scriban -d data.json

# Use remote template by GUID
loro transform --guid 72d561bf-3c17-4b34-b48d-cee00f1f0e1e -d data.json

# Save to file
loro transform template.scriban -d data.json -o output.html

Integration Examples

Build Script Integration

#!/bin/bash
# Generate reports using templates

echo "Generating monthly report..."
loro remote 72d561bf-3c17-4b34-b48d-cee00f1f0e1e \
  -d monthly-data.json \
  -o reports/monthly-report.html

echo "Generating invoice..."
loro remote 22222222-2222-2222-2222-222222222222 \
  -d invoice-data.json \
  -o invoices/invoice-$(date +%Y%m%d).html

echo "Reports generated successfully!"

Package.json Scripts

{
  "scripts": {
    "generate-docs": "loro remote DOC_TEMPLATE_GUID -d docs-data.json -o README.md",
    "build-emails": "loro list -s email | xargs -I {} loro remote {} -d user-data.json",
    "deploy-templates": "loro stats && npm run build"
  }
}

Environment Variables

You can also configure the CLI using environment variables:

export LORO_API_KEY="your-api-key"
export LORO_API_URL="https://api.lorotemplates.com"

# Now you can use CLI without --api-key flag
loro remote 72d561bf-3c17-4b34-b48d-cee00f1f0e1e -d data.json

10. 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