Skip to main content

JCB! Custom Codes

create and manage custom logic that can be reused, shared, and even injected into your component code at compile time

What Are Custom Codes in JCB?

Custom Codes in JCB allow you to create and manage custom logic that can be reused, shared, and even injected into your component code at compile time. This feature supports two advanced use cases:

  1. Reusable Code Blocks with Argument Injection
    called: JCB (manual)
  2. Persistent File Modification via Insert/Replace Tags
    called: Hash (automation)

1. Reusable Code Injection with [CUSTOMCODE=...] (JCB manual)

This method allows you to define a custom code block once and inject it into any JCB-supported code area using a placeholder like:

[CUSTOMCODE=mainReadmePackageFooter]

You can also pass dynamic arguments into these placeholders:

[CUSTOMCODE=mainReadmePackageFooter+foo,bar,baz]

Your custom code may then reference these values using zero-based placeholders:

  • [[[arg0]]]foo
  • [[[arg1]]]bar
  • [[[arg2]]]baz
🧠 Encoding Special Characters:
To include reserved characters in arguments, use these HTML-safe equivalents:
[[   ]]   ,,   ++   ==

Scope of Use:

  • Works in any JCB code area (PHP, JS, HTML, etc.)
  • Can be used within other custom codes
  • Cannot be used inside its own definition or in IDE hash automation code

Note on Editor Sync:

At present, argument-based custom codes cannot be reversed back from the compiled project into the UI without losing the [[[argX]]] placeholders. All updates for such code must be done via the JCB UI until this limitation is resolved.


2. Persistent File Overrides via Insert/Replace Tags (Hash automation)

When working with a compiled component installed on the same Joomla instance as JCB, you can insert or replace blocks of code inside the actual generated files using special comment tags like:

/***[INSERT<>$$$$]***/
// your code
/***[/INSERT<>$$$$]***/

JCB scans for these tags and:

  • Extracts the content
  • Stores it in the Custom Code UI
  • Keeps track of the file and line number
  • Re-injects the code on future compilations

This works for both PHP and HTML using appropriately formatted tag styles.

If the injection location becomes ambiguous, JCB will:

  • Comment out the custom code block
  • Warn you about the issue
  • Preserve the code for manual review

📘 Full tag syntax reference available here:
👉 TIPS: Custom Code


3. Reverse Engineering of Language Strings

When custom code uses Text::_('SOME_CONSTANT') language strings, JCB automatically converts them back into their readable string form when importing into the editor. This improves maintainability by letting you work with the original values rather than language constants.


4. Customization, Forking, and Version Control

As with other JCB entities, Custom Codes support a Git-based workflow:

  • Init: Import from a repository
  • Reset: Overwrite with the repository version
  • Push: Update a shared repository if you have write access
  • Fork: Maintain and manage your own custom code set

This design encourages collaborative and modular development across multiple JCB projects.


Index of Custom Codes

All used in Joomla Component Builder
Source - Mirror - Download