Custom Code Block icon
Module Id
custom-code-block
Group Id
org.jahia.community
Updated
Requires Jahia
8.2.0.0
Author
pvollenweider
Category
Tools and Utilities
Status
COMMUNITY info

Custom Code Block group_work

html css javascript code

Jahia module providing a jnt:customCodeBlock component that allows editors to inject raw HTML, CSS and JavaScript directly into a page.

The three fields use the CodeMirror selector type for syntax highlighting:

Property Type i18n Description
html String yes Injected directly in the page (HTML, scripts, embeds…)
css String no Injected in <head> inside a <style> tag
js String no Injected before </body> inside a <script> tag (no script tags needed)

The three fields use the CodeMirror selector type for syntax highlighting.

Once installed, the module must be enabled per site — go to each site's settings and activate it from the modules list.

The component will then be available in the Advanced Content category when adding content in page edit mode.

Dependencies & Dependants

Dependants
  • NONE

FAQ

Usage

Can I put any code in the HTML field?
Yes — including <script> tags, iframes, and third-party embeds.

Why isn’t my JS running?
The JS field is automatically wrapped in <script> tags — do not add them manually.

Does the CSS apply to the whole page or just the component?
It applies to the whole page. If needed, scope your styles with a specific class.

Can I have different HTML content per language?
Yes — the HTML field is i18n. CSS and JS are shared across languages.


Third-party integrations (HubSpot, Typeform, etc.)

How do I embed a third-party widget?
Paste the full snippet into the HTML field.

Will an external script be loaded multiple times if the component is used several times on the same page?
Yes, if included in the HTML field. Using the JS field avoids this, as scripts are deduplicated via Jahia’s addResources.


Security / Editorial

Can any editor use this component?
No — access depends on Jahia permissions. The jmix:accessControllableContent mixin allows restriction per role.

Is the content sanitized?
No — it is injected as-is. Access should be restricted to trusted users only.


Technical

Where are CSS and JS injected in the page?
CSS and JS are injected inline via template:addResources, alongside other page resources.

Is this component compatible with Jahia caching?
Yes, but injected code runs on each render and may impact behavior depending on its nature.

How To Install

Please read the dedicated tutorial on https://academy.jahia.com/tutorials-get-started/java-developers/installing-a-module and select the Custom Code Block module from the store.

Once installed, the module must be enabled per site.

Images