Include Files
Include files allow you to reuse template snippets across multiple templates. Instead of duplicating the same code in every template, write it once in an include file and reference it everywhere.
Include Syntax
{:include: path/file.ext:}
The path/file.ext is relative to your project's template directory.
Basic Example
File: templates/header.template
/**
* Generated by Scoriet
* Project: {:projectname:}
* Database: {:projectdatabase:}
*/
File: templates/UserModel.template
{:include: header.template:}
class User {
public $id;
public $username;
}
Generated Output:
/**
* Generated by Scoriet
* Project: MyEcommerceApp
* Database: ecommerce_prod
*/
class User {
public $id;
public $username;
}
Common Use Cases
1. File Headers and Metadata
Create a standard header that all templates share:
File: templates/_header.template
/**
* AUTO-GENERATED CODE - DO NOT MODIFY MANUALLY
* Generated by Scoriet on 2026-04-13
*
* Project: {:projectname:}
* Database: {:projectdatabase:}
* Language: {:defaultlanguage:}
*
* Changes will be lost when code is regenerated.
* Modify the template to make permanent changes.
*/
File: templates/Model.template
{:include: _header.template:}
namespace {:pascalcase(projectname):}\Models;
class {:pascalcase(tablename):} {
// Model implementation
}
2. Namespace/Package Declarations
File: templates/_php_namespace.template
namespace {:pascalcase(projectname):}\Models;
use Illuminate\Database\Eloquent\Model;
File: templates/PHPModel.template
{:include: _php_namespace.template:}
class {:pascalcase(tablename):} extends Model {
protected $table = '{:tablename:}';
protected $fillable = [
{:for fieldsnokey:}
'{:item.name:}',
{:endfor:}
];
}
3. Validation Rules Template
File: templates/_validation_rules.template
public function rules() {
return [
{:for nmaxitems:}
'{:item.name:}' => '{:if item.isnullable==false:}required|{:endif:}
{:if item.type=="varchar":}string|max:{:item.length:}{:elseif item.type=="int" || item.type=="bigint":}integer{:elseif item.type=="datetime":}date{:else:}string{:endif:}',
{:endfor:}
];
}
File: templates/FormRequest.template
{:include: _php_namespace.template:}
class {:pascalcase(tablename):}Request extends Request {
{:include: _validation_rules.template:}
}
4. License Headers
File: templates/_mit_license.template
/*
* MIT License
*
* Copyright (c) 2026 Scoriet Generated Code
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*/
File: templates/SourceFile.template
{:include: _mit_license.template:}
// Your generated code here
5. Relationship Helper Methods
File: templates/_relationships.template
{:for foreign:}
public function {:camelcase(singular(item.linktable)):}() {
return $this->belongsTo({:pascalcase(singular(item.linktable)):}::class, '{:item.name:}', '{:item.linkfield:}');
}
{:endfor:}
File: templates/Model.template
class {:pascalcase(tablename):} extends Model {
protected $table = '{:tablename:}';
// Relationships
{:include: _relationships.template:}
}
Include File Organization
Recommended Directory Structure
templates/
├── _includes/
│ ├── headers/
│ │ ├── php_file_header.template
│ │ ├── java_file_header.template
│ │ ├── csharp_file_header.template
│ │ └── mit_license.template
│ ├── namespaces/
│ │ ├── php_namespace.template
│ │ └── java_package.template
│ ├── common/
│ │ ├── validation_rules.template
│ │ ├── relationships.template
│ │ └── constants.template
│ └── patterns/
│ ├── model_properties.template
│ ├── getter_setter.template
│ └── factory_methods.template
├── php/
│ ├── Model.template
│ ├── Migration.template
│ ├── Controller.template
│ └── Request.template
├── java/
│ ├── Entity.template
│ ├── Repository.template
│ └── Service.template
└── csharp/
├── Model.template
├── DbContext.template
└── Repository.template
Using Subdirectories
{:include: _includes/headers/php_file_header.template:}
{:include: _includes/namespaces/php_namespace.template:}
class {:pascalcase(tablename):} {
{:include: _includes/common/validation_rules.template:}
{:include: _includes/patterns/model_properties.template:}
}
Include File Best Practices
1. Use descriptive names with underscore prefix
Include files are supporting files, not primary templates. Use a naming convention:
_header.template— File headers_namespace.template— Namespace declarations_footer.template— File footers
2. Make includes standalone or simple
Include files should be:
- Self-contained (don't require external context)
- Small (under 50 lines usually)
- Focused on one purpose
If an include file becomes complex, break it into smaller includes or use a code block in the main template.
3. Keep includes language-agnostic when possible
Good:
{:include: _header.template:}
This works for any language if the header is generic.
Avoid language-specific paths unless necessary:
{:include: php/_php_namespace.template:}
Consider using conditional includes based on language instead.
4. Document what each include expects
Add comments to include files explaining their purpose:
File: _relationships.template
{:for foreign:}
// Include: _relationships.template
// Generates one relationship method per foreign key
// Requires: loop over {:for foreign:} collection
public function {:camelcase(singular(item.linktable)):}() {
return $this->belongsTo({:pascalcase(singular(item.linktable)):}::class);
}
{:endfor:}
5. Avoid deep nesting of includes
Don't create includes that include other includes that include yet more includes. Stick to 1-2 levels deep.
Good:
Main template
├─ Include A
└─ Include B
Avoid:
Main template
└─ Include A
└─ Include B
└─ Include C
6. Use consistent include paths
Establish a convention:
- Always use relative paths from the templates directory
- Always use forward slashes, even on Windows
- Always include the file extension
Consistent:
{:include: _includes/headers/standard.template:}
{:include: patterns/relationships.template:}
Avoid mixing:
{:include: _includes\headers\standard.template:}
{:include: patterns/relationships}
7. Version includes together with main templates
If you update an include file, test all templates that use it. Include files are shared code — a change affects everything that uses it.
Advanced Include Patterns
Pattern 1: Language-Specific Includes
Use conditionals to include language-specific content:
File: templates/Model.template
{:include: _header.template:}
{:if selectedlanguage=="PHP":}
{:include: php/_model_class.template:}
{:elseif selectedlanguage=="Java":}
{:include: java/_entity.template:}
{:elseif selectedlanguage=="CSharp":}
{:include: csharp/_model.template:}
{:endif:}
Pattern 2: Optional Sections
Include files for optional features:
File: templates/Model.template
{:include: _header.template:}
class {:pascalcase(tablename):} {
// Basic properties
{:for nmaxitems:}
public $item.name:};
{:endfor:}
{:if nmaxfiles > 5:}
// Only include helpers for databases with many tables
{:include: _helper_methods.template:}
{:endif:}
}
Pattern 3: Template Composition
Build complex templates from multiple includes:
File: templates/FullModel.template
{:include: _header.template:}
{:include: namespaces/php_namespace.template:}
class {:pascalcase(tablename):} extends Model {
{:include: common/model_properties.template:}
{:include: common/relationships.template:}
{:include: patterns/getter_setter.template:}
{:include: patterns/factory_methods.template:}
{:include: patterns/validation.template:}
}
{:include: _footer.template:}
Troubleshooting Includes
Issue: Include Not Found
Error: "Template not found: path/file.template"
Solution:
- Check the file exists in your template directory
- Verify the path is relative to the templates directory
- Check spelling and case sensitivity (some systems are case-sensitive)
- Use forward slashes:
_includes/file.template, not_includes\file.template
Issue: Include Produces Wrong Output
Cause: Include files have access to the same context as the main template. If the include uses {:nmaxitems:} and you're in a different loop context, it may be wrong.
Solution: Make sure includes work in their intended context. Test includes separately if possible.
Issue: Circular Include References
Problem: Include A includes Include B, and Include B includes Include A
Solution: This creates infinite recursion and will fail. Avoid circular references. Organize includes in a hierarchy: core → building blocks → composed templates.
Issue: Variable Scope in Includes
Question: Can includes access loop variables like {:nCount:} or {:item.name:}?
Answer: Yes! Includes share the same scope as the main template. If you're in a loop when you include a file, the include can use the loop variables.
Example:
File: _item_wrapper.template
<div class="item item-{:nCount:}">
{:item.name:}
</div>
File: ListTemplate.template
{:for nmaxitems:}
{:include: _item_wrapper.template:}
{:endfor:}
Output:
<div class="item item-1">
id
</div>
<div class="item item-2">
username
</div>
Include Examples
Complete Real-World Example: PHP Model Generation
File: _includes/headers/php_header.template
<?php
/**
* AUTO-GENERATED - Do not modify manually
* Generated by Scoriet for {:projectname:}
* {@:projectdatabase:}
*/
File: _includes/namespaces/php_models.template
namespace {:pascalcase(projectname):}\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
File: _includes/patterns/model_timestamps.template
public $timestamps = true;
protected $dates = [
{:for nmaxitems:}
{:if item.type=="datetime" || item.endswith("_at"):}
'{:item.name:}',
{:endif:}
{:endfor:}
];
File: _includes/patterns/fillable_fields.template
protected $fillable = [
{:for fieldsnokey:}
'{:item.name:}',
{:endfor:}
];
File: _includes/patterns/relationships.template
{:for foreign:}
public function {:camelcase(singular(item.linktable)):}() {
return $this->belongsTo({:pascalcase(singular(item.linktable)):}::class, '{:item.name:}', '{:item.linkfield:}');
}
{:endfor:}
File: templates/EloquentModel.template
{:include: _includes/headers/php_header.template:}
{:include: _includes/namespaces/php_models.template:}
class {:pascalcase(tablename):} extends Model {
use HasFactory;
{:include: _includes/patterns/model_timestamps.template:}
{:include: _includes/patterns/fillable_fields.template:}
{:include: _includes/patterns/relationships.template:}
}
Generated Output:
<?php
/**
* AUTO-GENERATED - Do not modify manually
* Generated by Scoriet for MyEcommerceApp
* ecommerce_prod
*/
namespace MyEcommerceApp\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Users extends Model {
use HasFactory;
public $timestamps = true;
protected $dates = [
'created_at',
'updated_at',
];
protected $fillable = [
'username',
'email',
'password',
];
public function roles() {
return $this->belongsTo(Roles::class, 'role_id', 'id');
}
}
Next: Follow the complete Generation Workflow to see how all these features work together in practice.