Template Syntax Reference
This is the complete reference for Scoriet's template syntax. Every {:...:} marker available in the engine is documented here with examples. Use this as your lookup guide when writing templates.
Syntax Overview
Scoriet templates use the {:...:} marker syntax to embed dynamic content. This syntax:
- Avoids conflicts with common programming language braces like
{}in C#, Java, and JavaScript - Is visually distinct, making it easy to spot dynamic content
- Supports nesting within loops and conditionals
Basic Structure
Plain text here
{:projectname:}
More plain text
{:for nmaxitems:}
Loop content with {:item.name:}
{:endfor:}
The engine processes markers in sequence, replacing each {:...:} with its value.
System Variables
System variables provide context about your project, database, and current generation state. They're available everywhere in your template.
Project & Database Context
| Variable | Type | Description | Example |
|---|---|---|---|
{:projectname:} | string | Name of the current project | MyEcommerceApp |
{:projectid:} | string | Unique project identifier | proj_abc123def456 |
{:projectdatabase:} | string | Connected database name | ecommerce_prod |
{:defaultlanguage:} | string | Primary output language | PHP, Java, C# |
{:languageid:} | string | Language identifier | php, java, csharp |
{:selectedlanguage:} | string | Currently selected output language | PHP |
File & Output Context
| Variable | Type | Description | Example |
|---|---|---|---|
{:filename:} | string | Output filename being generated | UserModel.php |
{:tablename:} | string | Current table name (if applicable) | users |
Counting & Iteration Context
| Variable | Type | Description | Example |
|---|---|---|---|
{:nmaxitems:} | integer | Field count in current table | 7 |
{:nmaxfiles:} | integer | Total table count in database | 15 |
{:nmaxlanguages:} | integer | Total language count | 3 |
Context-Aware Variables: {:nmaxitems:} changes depending on context. Outside a loop, it refers to the first table's field count. Inside {:for nmaxitems:}, it refers to the current table's field count. Inside {:for nmaxfiles:}, it refers to the current table's field count when accessed in nested iteration.
System Variable Examples
Example 1: Project Header Comment
/**
* Generated by Scoriet
* Project: {:projectname:}
* Database: {:projectdatabase:}
* Language: {:defaultlanguage:}
* File: {:filename:}
*/
Output:
/**
* Generated by Scoriet
* Project: MyEcommerceApp
* Database: ecommerce_prod
* Language: PHP
* File: UserModel.php
*/
Example 2: Class Name from Project
namespace {:pascalcase(projectname):};
class {:pascalcase(tablename):} {
// Class definition
}
Output:
namespace MyecommerceApp;
class Users {
// Class definition
}
Example 3: Configuration Comment
# Configuration for {:projectname:}
# Database: {:projectdatabase:}
# Generated for: {:defaultlanguage:}
# Table Count: {:nmaxfiles:}
# Current Table Fields: {:nmaxitems:}
Output:
# Configuration for MyEcommerceApp
# Database: ecommerce_prod
# Generated for: PHP
# Table Count: 15
# Current Table Fields: 7
Item Object Properties
When iterating with loops, each item (field, table, constraint) has properties accessible via item.property syntax. These properties enable conditional generation based on field characteristics.
Field Item Properties
Available when inside {:for nmaxitems:}, {:for fieldsnokey:}, {:for fieldsnoblob:}:
| Property | Type | Description | Example |
|---|---|---|---|
item.name | string | Field name | user_id, created_at |
item.type | string | Database type | bigint, varchar, text, datetime |
item.controltype | string | UI control type | TextField, NumberField, DateField |
item.caption | string | Display label | User ID, Created At |
item.isprimarykey | boolean | Is primary key? | true, false |
item.isunique | boolean | Has unique constraint? | true, false |
item.isnullable | boolean | Allows NULL? | true, false |
item.linktable | string | Foreign key target table | users, products |
item.linkfield | string | Foreign key target field | id, product_id |
item.length | integer | Character length / precision | 255, 11 |
item.default | string | Default value | NULL, 0, CURRENT_TIMESTAMP |
Case Conversion Properties
While looping, you can access case-converted versions of item names:
| Property | Description | Example |
|---|---|---|
item.pascalcase or {:pascalcase(item.name):} | PascalCase | UserId, CreatedAt |
item.camelcase or {:camelcase(item.name):} | camelCase | userId, createdAt |
item.snakecase | snake_case | user_id, created_at |
item.kebabcase | kebab-case | user-id, created-at |
PascalCase conversion: The functions {:pascalcase(item.name):} and item.pascalcase are equivalent. You can use either. Use the function form for more flexibility.
Item Property Examples
Example 1: Generate Only Non-NULL Fields
{:for nmaxitems:}
{:if item.isnullable==false:}
public $item.name:}; // Required field
{:endif:}
{:endfor:}
Output:
public $id; // Required field
public $username; // Required field
public $created_at; // Required field
Example 2: Type-Specific Property Handling
{:for nmaxitems:}
{:if item.type=="varchar":}
public string $item.camelcase:};
{:elseif item.type=="int":}
public int $item.camelcase:};
{:elseif item.type=="datetime":}
public DateTime $item.camelcase:};
{:else:}
public mixed $item.camelcase:};
{:endif:}
{:endfor:}
Output:
public string $userId;
public int $age;
public DateTime $createdAt;
public mixed $metadata;
Example 3: Foreign Key Detection
{:for nmaxitems:}
{:if item.linktable!="":}
public $item.name:}; // FK -> {:item.linktable:}({:item.linkfield:})
{:endif:}
{:endfor:}
Output:
public $user_id; // FK -> users(id)
public $product_id; // FK -> products(id)
Text Case Conversion
Scoriet provides built-in case conversion functions for transforming text. These are essential for generating idiomatic code in different languages.
Function Syntax
{:pascalcase(text):}
{:camelcase(text):}
{:snakecase(text):}
{:kebabcase(text):}
{:uppercase(text):}
{:lowercase(text):}
{:capitalize(text):}
Case Conversion Examples
Input: user_profile_name
| Function | Output |
|---|---|
{:pascalcase(...):} | UserProfileName |
{:camelcase(...):} | userProfileName |
{:snakecase(...):} | user_profile_name |
{:kebabcase(...):} | user-profile-name |
{:uppercase(...):} | USER_PROFILE_NAME |
{:lowercase(...):} | user_profile_name |
{:capitalize(...):} | User_profile_name |
Real-World Example: Multi-Language Class Generation
{:for nmaxfiles:}
// PHP
class {:pascalcase(item.name):} {
}
// JavaScript
class {:pascalcase(item.name):} {
}
// Python
class {:pascalcase(item.name):}:
pass
// Go
type {:pascalcase(item.name):} struct {
}
{:endfor:}
Loop Syntax
Loop markers iterate over collections of items. See Loops and Iteration for complete details.
Loop Marker Reference
{:for nmaxitems:}
Loop body — iterates over all fields
{:endfor:}
{:for nmaxfiles:}
Loop body — iterates over all tables
{:endfor:}
{:for constraints:}
Loop body — iterates over all constraints
{:endfor:}
{:for keys:}
Loop body — iterates over key fields only
{:endfor:}
{:for foreign:}
Loop body — iterates over foreign keys only
{:endfor:}
{:for fieldsnokey:}
Loop body — iterates over non-key fields
{:endfor:}
{:for fieldsnoblob:}
Loop body — iterates over non-BLOB fields
{:endfor:}
Loop variables (inside loops):
{:nCount:}— 1-based counter (1, 2, 3, ...){:i:}— 0-based index (0, 1, 2, ...){:item.*:}— Item properties
Conditional Syntax
Conditional markers enable logic-based code generation. See Conditionals for complete details.
If/Else Syntax
{:if condition:}
Output if true
{:endif:}
{:if condition:}
Output if true
{:else:}
Output if false
{:endif:}
{:if condition1:}
Output if condition1 is true
{:elseif condition2:}
Output if condition2 is true
{:else:}
Output if both false
{:endif:}
Condition Syntax
Conditions compare item properties or variables using these operators:
{:if item.type=="varchar":} // Equality
{:if item.isprimarykey==true:} // Boolean
{:if item.isnullable!=true:} // Not equal
{:if item.length > 100:} // Greater than
{:if item.length < 50:} // Less than
{:if item.length >= 255:} // Greater or equal
{:if item.length <= 20:} // Less or equal
{:if item.type=="varchar" && item.length > 100:} // AND
{:if item.type=="int" || item.type=="bigint":} // OR
{:if !item.isnullable:} // NOT
{:if item.name.contains("user"):} // String contains
{:if item.name.startswith("is_"):} // Starts with
{:if item.name.endswith("_at"):} // Ends with
String Functions
Functions for text manipulation. All functions use the {:function(args):} syntax.
String Functions Reference
| Function | Syntax | Description | Example |
|---|---|---|---|
| Upper | {:upper(text):} | Convert to UPPERCASE | Input: hello → Output: HELLO |
| Lower | {:lower(text):} | Convert to lowercase | Input: HELLO → Output: hello |
| Capitalize | {:capitalize(text):} | Capitalize first letter | Input: hello → Output: Hello |
| Length | {:length(text):} | String length as integer | Input: hello → Output: 5 |
| Substring | {:substr(text, start, len):} | Extract substring | Input: hello, 1, 3 → Output: ell |
| Replace | {:replace(text, old, new):} | Replace text | Input: hello, l, L → Output: heLLo |
Word Functions
Functions for linguistic transformations.
| Function | Syntax | Description | Example |
|---|---|---|---|
| Plural | {:plural(word):} | Convert to plural | Input: user → Output: users |
| Singular | {:singular(word):} | Convert to singular | Input: users → Output: user |
Pluralization works for English. Irregular plurals (man → men, child → children) are supported. Non-English pluralization may not work correctly.
Escaping Scoriet Syntax
To output literal {:...:} text without triggering processing, use a backslash:
Template:
Literal marker: \{:projectname:}
This will output: \{:for nmaxitems:}...{:endfor:}
Generated Output:
Literal marker: {:projectname:}
This will output: {:for nmaxitems:}...{:endfor:}
When to Escape
- Generating template files that use Scoriet syntax
- Documentation about Scoriet
- Code examples in generated comments
- Configuration files with brace syntax
Escaping Examples
{:code:}
// Escape to show template syntax in comments
// Example: \{:for nmaxitems:}...\{:endfor:}
{:codeend:}
Output:
// Escape to show template syntax in comments
// Example: {:for nmaxitems:}...{:endfor:}
Whitespace Handling
Scoriet preserves whitespace exactly as written in the template. Use this for controlling indentation and line breaks in generated code.
Whitespace Rules
- Spaces and tabs in the template appear in the output exactly
- Line breaks (newlines) are preserved
- Blank lines are preserved (use carefully — they add whitespace to output)
Whitespace Example: Controlling Indentation
class User {
{:for nmaxitems:}
public $item.name:};
{:endfor:}
}
Output:
class User {
public $id;
public $username;
public $email;
}
The 4-space indentation before public is preserved from the template.
Common Whitespace Mistakes
Problem 1: Extra blank lines
Template:
public function create() {
}
Creates extra blank lines in output. Solution: Remove blank lines from template if you don't want them in output.
Problem 2: Loop indentation
Template:
{:for nmaxitems:}public $item.name:};
{:endfor:}
Generated:
public $id;
public $username;
public $email;
No indentation because the template doesn't have it. Add spaces before public if you want indentation.
Include Syntax
Include files to embed reusable template snippets. See Include Files for details.
{:include: path/file.ext:}
The path is relative to your project's template directory.
Include Examples
// File: templates/classHeader.template
/**
* Generated class
* Table: {:tablename:}
*/
// File: templates/UserModel.template
{:include: classHeader.template:}
class User {
// Class body
}
Complete Template Example
Here's a real template combining multiple features:
{:include: header.template:}
namespace {:pascalcase(projectname):}\Models;
/**
* {@pascalcase(tablename):} Model
* Fields: {:nmaxitems:}
*/
class {:pascalcase(tablename):} {
// Properties
{:for nmaxitems:}
/**
* @var {:item.type:}
*/
public \$item.name:};
{:endfor:}
// Validation Rules
{:for nmaxitems:}
{:if item.isnullable==false:}
// Field: {:item.name:} (required)
{:endif:}
{:endfor:}
// Primary Key
{:for keys:}
public const PRIMARY_KEY = '{:item.name:}';
{:endfor:}
}
This template demonstrates:
- Include files (
{:include:}) - Case conversion (
{:pascalcase(...):}) - System variables (
{:projectname:},{:tablename:},{:nmaxitems:}) - Loops (
{:for nmaxitems:},{:for keys:}) - Conditionals (
{:if item.isnullable==false:}) - Item properties (
{:item.name:},{:item.type:})
Quick Reference Cheat Sheet
Variables: {:projectname:}, {:tablename:}, {:nmaxitems:}
Loops: {:for nmaxitems:}...{:endfor:}
Conditionals: {:if condition:}...{:endif:}
Functions: {:upper(text):}, {:camelcase(text):}, {:plural(word):}
JavaScript: {:code:}...{:codeend:}
Include: {:include: path/file.ext:}
Escape: \{:...:}
Next: Learn how to use loops effectively in Loops and Iteration, or explore conditionals in Conditionals.