{"id":28496214,"url":"https://github.com/danedens/node-red-contrib-file-template","last_synced_at":"2025-06-10T14:03:33.902Z","repository":{"id":297165865,"uuid":"995851151","full_name":"DanEdens/node-red-contrib-file-template","owner":"DanEdens","description":"A Node-RED node that loads HTML template content from file system, with file watching and dynamic reloading","archived":false,"fork":false,"pushed_at":"2025-06-04T05:33:17.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-04T12:03:20.135Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DanEdens.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-04T05:22:58.000Z","updated_at":"2025-06-04T05:33:19.000Z","dependencies_parsed_at":"2025-06-04T12:03:24.902Z","dependency_job_id":"64d2b516-e680-48a4-a9aa-73f68441b1db","html_url":"https://github.com/DanEdens/node-red-contrib-file-template","commit_stats":null,"previous_names":["danedens/node-red-contrib-file-template"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanEdens%2Fnode-red-contrib-file-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanEdens%2Fnode-red-contrib-file-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanEdens%2Fnode-red-contrib-file-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanEdens%2Fnode-red-contrib-file-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DanEdens","download_url":"https://codeload.github.com/DanEdens/node-red-contrib-file-template/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanEdens%2Fnode-red-contrib-file-template/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":258708898,"owners_count":22744975,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-08T12:06:44.311Z","updated_at":"2025-06-10T14:03:33.893Z","avatar_url":"https://github.com/DanEdens.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-red-contrib-file-template\n\nA Node-RED node that loads HTML template content from the filesystem with automatic file watching and reloading, perfect for managing large template files externally.\n\n## Features\n\n- 📁 **File-based Templates**: Load HTML templates from the filesystem instead of embedding them in flows\n- 🔄 **Auto-reload**: Automatically watches template files for changes and reloads content\n- 🎯 **Mustache Support**: Built-in support for Mustache/Handlebars-style variable substitution\n- 📊 **Status Indicators**: Visual feedback on file load status and errors\n- 🛡️ **Error Handling**: Graceful fallback to inline templates when files are unavailable\n- ⚡ **Performance**: Only reloads files when they actually change (based on modification time)\n\n## Installation\n\n### Via Node-RED Palette Manager\n1. Go to Node-RED settings → Manage Palette → Install\n2. Search for `node-red-contrib-file-template`\n3. Click Install\n\n### Via npm\n```bash\ncd ~/.node-red\nnpm install node-red-contrib-file-template\n```\n\n### Manual Installation\n```bash\ngit clone https://github.com/danedens/node-red-contrib-file-template.git\ncd node-red-contrib-file-template\nnpm install\nnpm link\ncd ~/.node-red\nnpm link node-red-contrib-file-template\n```\n\n## Usage\n\n### Basic Usage\n\n1. Drag the **file-template** node from the function category into your flow\n2. Double-click to configure:\n   - **Template File**: Path to your HTML template file (e.g., `templates/dashboard.html`)\n   - **Template Data**: Message property containing data for substitution (default: `payload`)\n   - **Template Format**: Choose Handlebars/Mustache for variable substitution or Plain HTML\n3. Connect your data source to the input\n4. Connect the output to a dashboard template node or HTTP response\n\n### Configuration Options\n\n| Option | Description | Default |\n|--------|-------------|---------|\n| **Name** | Node display name | (auto-generated) |\n| **Template File** | Path to template file relative to Node-RED working directory | *required* |\n| **Template Format** | `handlebars` for variable substitution, `plain` for static HTML | `handlebars` |\n| **Template Data** | Message property containing template data | `payload` |\n| **Output** | Set `msg.template` as `string` or `parsed` object | `str` |\n| **Fallback Template** | Optional inline template if file loading fails | (empty) |\n\n### Example Flow\n\n```json\n[\n    {\n        \"id\": \"template-node\",\n        \"type\": \"file-template\",\n        \"name\": \"Dashboard Template\",\n        \"filename\": \"templates/TodoList.html\",\n        \"format\": \"handlebars\",\n        \"field\": \"payload\",\n        \"fieldType\": \"msg\",\n        \"output\": \"str\"\n    }\n]\n```\n\n## Template Syntax\n\n### Variable Substitution\nUse Mustache-style syntax for variable substitution:\n\n**Template File** (`templates/dashboard.html`):\n```html\n\u003cdiv class=\"dashboard\"\u003e\n    \u003ch1\u003e{{title}}\u003c/h1\u003e\n    \u003cp\u003eWelcome, {{user.name}}!\u003c/p\u003e\n    \u003cdiv class=\"stats\"\u003e\n        \u003cspan\u003eTotal Items: {{stats.total}}\u003c/span\u003e\n        \u003cspan\u003eCompleted: {{stats.completed}}\u003c/span\u003e\n    \u003c/div\u003e\n\u003c/div\u003e\n```\n\n**Input Message**:\n```javascript\n{\n    \"payload\": {\n        \"title\": \"My Dashboard\",\n        \"user\": {\n            \"name\": \"John Doe\"\n        },\n        \"stats\": {\n            \"total\": 25,\n            \"completed\": 18\n        }\n    }\n}\n```\n\n**Output** (`msg.template`):\n```html\n\u003cdiv class=\"dashboard\"\u003e\n    \u003ch1\u003eMy Dashboard\u003c/h1\u003e\n    \u003cp\u003eWelcome, John Doe!\u003c/p\u003e\n    \u003cdiv class=\"stats\"\u003e\n        \u003cspan\u003eTotal Items: 25\u003c/span\u003e\n        \u003cspan\u003eCompleted: 18\u003c/span\u003e\n    \u003c/div\u003e\n\u003c/div\u003e\n```\n\n### Nested Properties\nAccess nested object properties using dot notation:\n```html\n\u003cp\u003e{{user.profile.email}}\u003c/p\u003e\n\u003cp\u003e{{settings.theme.primaryColor}}\u003c/p\u003e\n```\n\n### Default Values\nIf a variable doesn't exist, it will be replaced with an empty string:\n```html\n\u003cp\u003e{{nonexistent.property}}\u003c/p\u003e  \u003c!-- Results in: \u003cp\u003e\u003c/p\u003e --\u003e\n```\n\n## File Watching\n\nThe node automatically watches your template files for changes:\n\n- ✅ **File Modified**: Automatically reloads content when you save changes\n- ⚠️ **File Deleted**: Shows warning status, falls back to inline template if available\n- 🔄 **File Restored**: Automatically detects when file is restored and reloads\n- 📊 **Status Updates**: Visual indicators show current file status\n\n## Status Indicators\n\n| Color | Meaning |\n|-------|---------|\n| 🟢 **Green** | Template file loaded successfully |\n| 🟡 **Yellow** | Using fallback inline template |\n| 🔴 **Red** | Error loading file or processing template |\n| ⚪ **Grey** | No file specified or node inactive |\n\n## Output Format\n\nThe node adds the processed template to `msg.template` and includes metadata:\n\n```javascript\n{\n    \"template\": \"\u003chtml\u003e...\u003c/html\u003e\",  // Processed template content\n    \"_fileTemplate\": {               // Metadata\n        \"filename\": \"templates/dashboard.html\",\n        \"lastModified\": 1640995200000,\n        \"length\": 2048,\n        \"format\": \"handlebars\"\n    }\n}\n```\n\n## Use Cases\n\n### Dashboard Templates\nPerfect for Node-RED dashboards with large HTML templates:\n```\n[data source] → [file-template] → [dashboard template]\n```\n\n### Web Applications\nGenerate dynamic web pages:\n```\n[HTTP request] → [data processing] → [file-template] → [HTTP response]\n```\n\n### Email Templates\nCreate dynamic email content:\n```\n[trigger] → [user data] → [file-template] → [email sender]\n```\n\n### Report Generation\nGenerate HTML reports from data:\n```\n[database query] → [data formatting] → [file-template] → [PDF converter]\n```\n\n## Advanced Features\n\n### Multiple Data Sources\nPull template data from different contexts:\n- `msg` - From incoming message (default)\n- `flow` - From flow context\n- `global` - From global context\n\n### Error Recovery\n- Automatic retry on file system errors\n- Fallback to inline template content\n- Graceful handling of malformed templates\n- Detailed error logging\n\n### Performance Optimization\n- File content caching\n- Modification time checking (only reload when changed)\n- Efficient file watching with chokidar\n- Memory-efficient string processing\n\n## Troubleshooting\n\n### Common Issues\n\n**Template file not found**\n- Verify the file path is relative to Node-RED working directory\n- Check file permissions\n- Ensure the file exists and is readable\n\n**Variables not substituting**\n- Verify the input data structure matches your template variables\n- Check that the data is in the specified message property (`payload` by default)\n- Ensure you're using correct Mustache syntax: `{{variable}}`\n\n**File watching not working**\n- Some file systems (like network drives) may not support file watching\n- Restart Node-RED if file watching stops working\n- Check Node-RED logs for file watcher errors\n\n### Debug Tips\n\n1. **Check Status**: Node status indicator shows current state\n2. **View Logs**: Check Node-RED debug panel for detailed error messages\n3. **Test Data**: Use a debug node to verify your input data structure\n4. **File Permissions**: Ensure Node-RED has read access to template files\n\n## Development\n\n### Local Development\n```bash\ngit clone https://github.com/danedens/node-red-contrib-file-template.git\ncd node-red-contrib-file-template\nnpm install\nnpm link\ncd ~/.node-red\nnpm link node-red-contrib-file-template\n# Restart Node-RED\n```\n\n### Testing\n```bash\nnpm test\n```\n\n### Contributing\n1. Fork the repository\n2. Create a feature branch\n3. Make your changes\n4. Add tests if applicable\n5. Submit a pull request\n\n## License\n\nMIT License - see [LICENSE](LICENSE) file for details.\n\n## Support\n\n- 🐛 **Issues**: [GitHub Issues](https://github.com/danedens/node-red-contrib-file-template/issues)\n- 💬 **Discussions**: [GitHub Discussions](https://github.com/danedens/node-red-contrib-file-template/discussions)\n- 📧 **Email**: your.email@example.com\n\n## Related Nodes\n\n- [node-red-contrib-file-function](https://flows.nodered.org/node/node-red-contrib-file-function) - File-based function nodes\n- [node-red-dashboard](https://flows.nodered.org/node/node-red-dashboard) - Dashboard templates\n- [node-red-node-email](https://flows.nodered.org/node/node-red-node-email) - Email integration\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanedens%2Fnode-red-contrib-file-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanedens%2Fnode-red-contrib-file-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanedens%2Fnode-red-contrib-file-template/lists"}