Skip to main content

Dynamic Placeholder Variable Injection

making your logic blocks smarter, reusable, and adaptive

What Is It?

When writing reusable Custom Code in JCB, you can include special variables or tags known as โ€œplaceholders.โ€ These placeholders are evaluated and replaced during the compile process. For example:

  • [[[view.name]]] โ†’ current view name
  • [[[field.name]]] โ†’ active field identifier
  • [[[joomla.version]]] โ†’ targeted Joomla version
  • [[[component.name]]] โ†’ your component's system name
  • [[[custom.myToken]]] โ†’ custom metadata or config tokens

This means your custom code blocks remain flexible and reusable across different views or components โ€” adjusting to the compilation context automatically.

Where Can They Be Used?

  • โœ… Inside Custom Code blocks
  • โœ… Inside Snippets
  • โœ… Inside Templates & Layouts
  • โœ… Inside field save/get logic
  • โœ… Inside Controller overrides
  • โœ… Inside Metadata & README auto-generation

Examples

  • Use [[[view.name]]] to load a script unique to the current view
  • Use [[[joomla.version]]] to conditionally adapt logic for Joomla 3, 4, or 5
  • Use [[[field.label]]] to dynamically document behavior or set context-aware JavaScript logic
  • Use [[[component.name]]] to ensure consistent namespace references

Key Benefits

  • ๐Ÿ” Code Reuse Across Contexts: Write one snippet or logic block and inject it anywhere โ€” dynamically adapting to the context.
  • ๐Ÿง  Context-Aware Logic: Custom Code that behaves differently depending on where it's compiled into.
  • ๐Ÿ“š Consistent Naming: Auto-injected values reduce the need for manual namespace declarations.
  • โš™๏ธ Metadata Automation: Use placeholders inside README.md, LICENSE, or config templates to auto-document builds.
  • ๐ŸŒ Joomla-Aware Tokens: Adapt your logic to changes across Joomla versions or target-specific features via dynamic tokens (JPK).

Supported Placeholder Types

  • Component-level (name, title, namespace)
  • View-level (name, type, access)
  • Field-level (name, label, value)
  • Joomla version & compatibility
  • Custom user-defined variables (via GUI or hardcoded)

Why It Matters

  • โœ… Removes hardcoding โ€” one code block fits many uses
  • โœ… Keeps your logic DRY and modular
  • โœ… Encourages logic abstraction and version-resilience
  • โœ… Enables per-context customization at scale

Conclusion

Dynamic placeholder variable injection is a core power of JCBโ€™s compilation system โ€” making your logic blocks smarter, reusable, and adaptive. Combined with multi-context binding and insert/replace tags, it gives you the flexibility of a templating language with the control of raw PHP โ€” all inside a graphical interface. Write logic once, inject it everywhere โ€” contextually and intelligently.

Summary

JCB allows you to define dynamic placeholders inside Custom Code blocks that are automatically replaced with real values during component compilation โ€” enabling context-aware logic insertion that adjusts based on the build environment, Joomla version, view, field, or any dynamic entity reference.