Skip to main content

Template-Based File Creation

Create custom file structures using dynamic templates โ€” compile-ready, logic-aware, and fully reusable.

What Is Template-Based File Creation?

Template-Based File Creation in JCB allows you to define your own PHP, XML, INI, JS, CSS, or HTML files using dynamic templates โ€” then have those files automatically generated as part of the componentโ€™s compiled output.

Templates can include custom logic, placeholders, Joomla data references, insert/replace tags, and even embedded PHP snippets. This lets you automate the creation of custom logic files, helper classes, JavaScript libraries, custom scripts, documentation, or anything else you want included in your component.

Rather than manually managing extra files outside of JCB, template-based files let you embed the logic inside your blueprint โ€” with full versioning, visibility, and round-trip support.

Key Features

  • ๐Ÿงฉ Define Your Own Files: Create template-based files of any format (e.g. .php, .xml, .js, .json, .ini, .md, .txt). You define:
    • The filename (can use placeholders)
    • The relative folder path in the component
    • The file contents (as a JCB template/snippet)
  • ๐Ÿง  Dynamic Placeholder System: Templates support:
    • Joomla Powers (JPK)
    • Custom variables
    • Field/View metadata
    • Entity IDs
    • Tags and insert/replace hooks
  • ๐Ÿ”„ Round-Trip Friendly: Files can include insert/replace tags for future syncing back into JCB.
  • ๐Ÿ“‚ Organized into Repositories: Templates are stored in JCBโ€™s internal repository system and reusable across projects.
  • ๐ŸŽ›๏ธ Compile-Time Control: Conditionally include files (e.g., only if a field exists or for a specific Joomla version).
  • ๐Ÿงฐ Linked to Layouts, Snippets, and Admin Views: Associate templates with:
    • Custom admin/site views
    • Layouts and rendering logic
    • Helper or service classes
    • Language or install scripts
  • ๐Ÿ–‹ Supports Comments, Metadata, and Versioning: Track changes and generate build reports for created/updated files.

Use Cases

  • Create a custom API helper (e.g., ApiHelper.php)
  • Include a version.txt or changelog.md file in your component
  • Add a JSON config file for a JS library
  • Generate an install script that adjusts Joomla core settings
  • Build a manifest fragment dynamically based on fields
  • Compile a language file for a custom CLI command

How to Use Template-Based File Creation

  1. Go to Components โ†’ JCB โ†’ Templates (or Snippets).
  2. Create a new file template:
    • Assign a name
    • Define the file path (e.g. /helpers/myhelper.php)
    • Write the file content using placeholders and logic
  3. Link the template to:
    • A View, Layout, or Admin View
    • Or set it to โ€œGlobalโ€ for all builds
  4. Compile the component.
  5. The file will be generated into the target directory inside the compiled ZIP.

๐Ÿง  Tip: Use the JCB Snippets system to inject repeated code blocks into your templates dynamically.

Conclusion

Template-Based File Creation is a powerful way to embed advanced logic, structure, and automation into your Joomla components โ€” all from within JCB. By defining your own files as templates, you gain complete control over your output while keeping everything versioned, reusable, and round-trip compatible.