Overview
User-defined templates allow you to create reusable code patterns for blocks and pipelines, enabling faster development and consistent coding standards across your organization. Templates can include placeholders for customization and can be shared across projects.Block Templates
Creating block templates
Block templates are reusable code patterns that can be customized with variables. They help standardize common patterns across your organization. Steps to create a block template:- Navigate to Templates - Click “Templates” in the left navigation menu
- Create new template - Click “New block template” button
- Define template properties:
- Template UUID - Enter a unique identifier (e.g.,
sql_data_loader
) - Block type - Select the type (Data loader, Transformer, Data exporter, etc.)
- Language - Choose the programming language (Python, SQL, R, etc.)
- Template UUID - Enter a unique identifier (e.g.,
- Edit template content - Write the template code with placeholders
- Save template - Click “Save template” to create the template
Template File Structure
When you create a block template, Mage automatically creates the following file structure:metadata.yaml
- Contains template metadata, block type, language, and other configuration{template_uuid}.py
- The actual template code file that users will customize
test_template
:
Template Library Interface
The template library provides a centralized location to manage all your block and pipeline templates: Template Library Features:- Template categories - Filter templates by type (Blocks or Pipelines)
- Pipeline template categories - Filter pipeline templates by type (Standard, Integration, Streaming)
- Search functionality - Find templates by name or description
- Template preview - View template details before using
- Template management - Edit, delete, or duplicate existing templates
- From left navigation - Click “Templates” to access the template library
- From pipeline editor - Use “Browse templates” when adding new blocks
- From pipeline creation - Select “From a template” when creating new pipelines
- Template organization - Templates are organized by type and category for easy discovery
- Switch to Pipelines tab - Click “PIPELINES” tab in the template library
- Filter by category - Select from Standard, Integration, or Streaming templates
- View template details - See template name, description, and metadata
- Select template - Click on a template to use it for creating new pipelines
Using block templates
Steps to use a block template:- Open pipeline editor - Navigate to the pipeline where you want to add the block
- Add new block - Click the ”+” button to add a new block
- Browse templates - Select “Browse templates” from the block creation options
- Select template - Choose the template you want to use from the available templates
- Name the block - Enter a specific name for your new block instance
- Customize as needed - Modify the generated code for your specific use case
Pipeline Templates
Creating pipeline templates
Pipeline templates define complete pipeline structures that can be customized for different use cases. Steps to create a pipeline template:- Navigate to pipelines page - Go to the main pipelines list view
- Right-click on a pipeline - Right-click on the pipeline you want to use as a template
- Select “Create template” - Choose “Create template” from the right-click context menu
- Configure template settings - Set template name, description, and other properties
- Save template - The pipeline structure will be saved as a reusable template
Using pipeline templates
Steps to use a pipeline template:- Navigate to the pipelines page in your project
- Click “New” button to open the pipeline creation menu
- Select “From a template” from the dropdown options
- Choose your template from the available pipeline templates
- Customize the pipeline - Modify blocks, connections, and settings as needed
- Save the pipeline with your specific configuration
Note: Pipeline templates are created from existing pipelines using the right-click context menu. This allows you to reuse successful pipeline patterns across your projects.
Best Practices
Template design
- Keep templates focused - Each template should serve a specific purpose
- Use clear variable names - Make variable purposes obvious
- Include comprehensive documentation - Explain usage and customization options
- Test with different configurations - Ensure templates work with various inputs
- Follow coding standards - Maintain consistent style and practices
Template maintenance
- Regular updates - Keep templates current with latest Mage features
- User feedback - Collect and incorporate user suggestions
- Performance optimization - Monitor and improve template performance
- Security review - Ensure templates follow security best practices