n8n-nodes-text-templater-jinja2
v1.0.3
Published
n8n node for text templating using Jinja2-like syntax
Downloads
10
Maintainers
Readme
n8n-nodes-text-templater-jinja2
An n8n community node for text templating using Jinja2-like syntax. Perfect for rendering dynamic prompts for LLMs and other text generation tasks.
Features
- Jinja2-compatible templating: Uses Nunjucks (a JavaScript implementation of Jinja2) for powerful templating
- Dynamic context: Supports JSON context variables and automatic access to input item data
- Error handling: Graceful error handling with detailed error messages
- n8n integration: Fully compatible with n8n workflows
Installation
Option 1: Install from npm (Recommended)
npm install n8n-nodes-text-templater-jinja2Option 2: Manual Installation
- Clone or download this repository
- Navigate to the project directory
- Install dependencies:
npm install - Build the project:
npm run build - Copy the
distfolder to your n8n custom nodes directory
Option 3: Docker Installation
For local development and testing with Docker, you can install the node in an n8n Docker container.
Method A: Using npm in Docker
Create a custom Dockerfile:
FROM n8nio/n8n:latest USER root # Install the custom node RUN npm install -g n8n-nodes-text-templater-jinja2 USER nodeBuild and run:
docker build -t n8n-with-templater . docker run -it --rm \ --name n8n-templater \ -p 5678:5678 \ -e N8N_BASIC_AUTH_ACTIVE=true \ -e N8N_BASIC_AUTH_USER=user \ -e N8N_BASIC_AUTH_PASSWORD=password \ n8n-with-templater
Method B: Manual Installation in Docker
Create a custom nodes directory:
mkdir -p ./custom-nodesClone and build the node:
cd custom-nodes git clone https://github.com/potnoddle/n8n-nodes-text-templater-jinja2.git cd n8n-nodes-text-templater-jinja2 npm install npm run build cd ../..Run n8n with volume mount:
docker run -it --rm \ --name n8n-templater \ -p 5678:5678 \ -v $(pwd)/custom-nodes:/home/node/.n8n/custom \ -e N8N_CUSTOM_EXTENSIONS=/home/node/.n8n/custom \ n8nio/n8n:latest
Method C: Using Docker Compose
Create a docker-compose.yml file:
version: '3.8'
services:
n8n:
image: n8nio/n8n:latest
ports:
- "5678:5678"
environment:
- N8N_BASIC_AUTH_ACTIVE=true
- N8N_BASIC_AUTH_USER=user
- N8N_BASIC_AUTH_PASSWORD=password
- N8N_CUSTOM_EXTENSIONS=/home/node/.n8n/custom
volumes:
- ./custom-nodes:/home/node/.n8n/custom
- n8n_data:/home/node/.n8n
command: n8n start
restart: unless-stopped
volumes:
n8n_data:Then run:
docker-compose up -dAccessing Your Node
Once n8n is running with the custom node installed:
- Open your browser to
http://localhost:5678 - Log in with the credentials you set
- In the workflow editor, search for "Text Templater (Jinja2)" in the nodes panel
- Drag and drop it into your workflow
Usage
Basic Example
- Add the "Text Templater (Jinja2)" node to your workflow
- Configure the node:
- Template:
Hello {{ name }}! Welcome to {{ location }}. - Context:
{"name": "John", "location": "n8n"}
- Template:
- Connect input data and run the workflow
Output: Hello John! Welcome to n8n.
Advanced Example with Input Data
Template:
Generate a summary for the following task:
Task: {{ $item.title }}
Description: {{ $item.description }}
Priority: {{ $item.priority }}
Please provide a concise summary in 2-3 sentences.Context: {"model": "gpt-4", "temperature": 0.7}
Input Item:
{
"title": "Implement user authentication",
"description": "Add OAuth2 login system with Google and GitHub providers",
"priority": "high"
}Rendered Output:
Generate a summary for the following task:
Task: Implement user authentication
Description: Add OAuth2 login system with Google and GitHub providers
Priority: high
Please provide a concise summary in 2-3 sentences.Node Properties
Template
- Type: String (multiline)
- Required: Yes
- Description: The Jinja2 template to render. Supports all Nunjucks/Jinja2 syntax including variables, filters, conditionals, and loops.
Context
- Type: JSON
- Required: Yes
- Description: JSON object containing variables available in the template. These are merged with the input item data.
Template Syntax
The node uses Nunjucks templating syntax, which is compatible with Jinja2:
Variables
{{ variable_name }}
{{ object.property }}
{{ array[0] }}Conditionals
{% if condition %}
Content if true
{% else %}
Content if false
{% endif %}Loops
{% for item in items %}
- {{ item.name }}
{% endfor %}Filters
{{ text | upper }}
{{ number | round(2) }}
{{ date | date('YYYY-MM-DD') }}Special Variables
$item: Contains the current input item's JSON data- All variables from the Context JSON are available at root level
Error Handling
If template rendering fails, the node will output:
error: The error message- All original input item data
Development
Prerequisites
- Node.js 16+
- npm or yarn
Setup
git clone <repository-url>
cd n8n-nodes-text-templater-jinja2
npm installBuild
npm run buildDevelopment Mode
npm run devTesting
npm testDeployment to n8n Community
1. Prepare for Publishing
Ensure your package.json has the correct metadata:
{ "name": "n8n-nodes-text-templater-jinja2", "version": "1.0.0", "description": "n8n node for text templating using Jinja2 syntax", "main": "dist/index.js", "keywords": ["n8n", "node", "templating", "jinja2"], "author": "Your Name", "license": "MIT" }Build the project:
npm run buildTest the built package locally
2. Publish to npm
npm login
npm publish3. Submit to n8n Community
- Go to the n8n Community Nodes page
- Click "Submit a Node"
- Fill out the submission form:
- Node Name: Text Templater (Jinja2)
- Package Name: n8n-nodes-text-templater-jinja2
- Description: n8n node for text templating using Jinja2-like syntax
- Tags: templating, text, jinja2, nunjucks
- Repository URL: Your GitHub repository URL
- Documentation URL: Link to this README
4. Community Guidelines
- Follow n8n's node development guidelines
- Ensure proper error handling
- Provide comprehensive documentation
- Test thoroughly before submission
- Use semantic versioning
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
MIT License - see LICENSE file for details
Support
- Create an issue on GitHub
- Check the n8n community forums
- Review the n8n documentation
Changelog
v1.0.0
- Initial release
- Basic Jinja2 templating functionality
- JSON context support
- Error handling
