# SOLVED: Setting "mode" in Code control (no syntax highlighter)

**URL:** <https://forum.bricksbuilder.io/t/solved-setting-mode-in-code-control-no-syntax-highlighter/2739>\
**Category:** Developers\
**Created:** [April 23, 2022, 8:47am UTC](https://forum.bricksbuilder.io/t/solved-setting-mode-in-code-control-no-syntax-highlighter/2739 "2022-04-23T08:47:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![wolfgang](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/wolfgang/32/26083_2.png) [@wolfgang](https://forum.bricksbuilder.io/u/wolfgang)\
**Post date:** [April 23, 2022, 8:47am UTC](https://forum.bricksbuilder.io/t/solved-setting-mode-in-code-control-no-syntax-highlighter/2739/1 "2022-04-23T08:47:37Z")

</div>

Hey there,  
I’m just playing around with the [Code Controls](https://academy.bricksbuilder.io/article/code-control/) and I’m a bit stuck.

The docs are prepared with a PHP Code-Input. I am trying to get a javascript input-field, but i’m not sure what to use for the “mode” key.

For example when I want to use CSS i have to set ‘mode’ =\> ‘css’ … that works, but I’m not sure which keyword is used for javascript?! 🙂

Tried to find something in the CodeMirror docs but without success. Have tried so far:

- JavaScript
- js
- JS
- javascript
- text/javascript

but unfortunately none of them highlight javascript-code! ☹

Appreciate any help! 🙂

Cheers  
Wolfgang

---

<div class="post-metadata">

**Author:** ![luistinygod](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/luistinygod/32/113_2.png) [@luistinygod](https://forum.bricksbuilder.io/u/luistinygod)\
**Post date:** [April 28, 2022, 3:49pm UTC](https://forum.bricksbuilder.io/t/solved-setting-mode-in-code-control-no-syntax-highlighter/2739/2 "2022-04-28T15:49:04Z")

</div>

Hello @wolfgang

The mode key is suppose to be `javascript` if you want to highlight JS code; but Bricks is only accepting `css` or `php`. I added an internal task so we could review this.

---

<div class="post-metadata">

**Author:** ![wolfgang](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/wolfgang/32/26083_2.png) [@wolfgang](https://forum.bricksbuilder.io/u/wolfgang)\
**Post date:** [April 29, 2022, 7:00am UTC](https://forum.bricksbuilder.io/t/solved-setting-mode-in-code-control-no-syntax-highlighter/2739/3 "2022-04-29T07:00:44Z")

</div>

Oh alright, I understand! Thanks a lot for that information, then I’m waiting for a fix here and using it without syntax highlighting meanwhile

---

<div class="post-metadata">

**Author:** ![thomas](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/thomas/32/3_2.png) [@thomas](https://forum.bricksbuilder.io/u/thomas)\
**Post date:** [May 4, 2022, 11:39am UTC](https://forum.bricksbuilder.io/t/solved-setting-mode-in-code-control-no-syntax-highlighter/2739/4 "2022-05-04T11:39:57Z")

</div>

Hi @wolfgang, I’ve added the JavaScript syntax highlighter in my local installation, and it does actually a worse job the the `php` mode. Which is also why we did not include the `mode: 'javascript'` for the Code control.

Could you share a screenshot of your custom element and the Code control with some JavaScript in it (in the builder), so I can better see the missing syntax highlight?

Please also paste this JS here as a code snippet. Then I can copy&paste it into my own installation to see where the highlighter is missing. Thank you!

---

<div class="post-metadata">

**Author:** ![wolfgang](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/wolfgang/32/26083_2.png) [@wolfgang](https://forum.bricksbuilder.io/u/wolfgang)\
**Post date:** [May 5, 2022, 9:42am UTC](https://forum.bricksbuilder.io/t/solved-setting-mode-in-code-control-no-syntax-highlighter/2739/5 "2022-05-05T09:42:35Z")

</div>

Hey Thomas,

for sure. You can see the code of the element itself here: [https://raw.githubusercontent.com/web-craft-design/bricks-elements/main/elements/codeBlock.php](https://raw.githubusercontent.com/web-craft-design/bricks-elements/main/elements/codeBlock.php)

That’s not the latest branch, on my local machine here I have changed mode: ‘js’ to mode:‘javascript’ which outputs the same behaviour, as mentioned!

The code-Highlighting for javascript is not existent in my installation here, not sure if I understand you correct, but if so, then you are saying that it works in your installation but isn’t very good, right?

Thats the screenshot of the code-control with some javascript in it:

 ![image](https://forum.bricksbuilder.io/uploads/default/original/2X/2/27ebd667ab1fe0527e91ee2312de8452bf147d0d.png)

The code itself is pretty simple. Just tried to put some different datatypes in it to see if it works, but nothing get’s highlighted, also the “indentation of the lines” (don’t know what the correct term is, hope you understand what i mean) doesn’t work here.

The Code:

```auto
function myFunction() {
var test = 'Test Console Log';
const anotherTest = 10;

console.log(test);

}

```

Cheers  
Wolfgang

---

<div class="post-metadata">

**Author:** ![thomas](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/thomas/32/3_2.png) [@thomas](https://forum.bricksbuilder.io/u/thomas)\
**Post date:** [May 8, 2022, 10:04am UTC](https://forum.bricksbuilder.io/t/solved-setting-mode-in-code-control-no-syntax-highlighter/2739/6 "2022-05-08T10:04:36Z")

</div>

Ok, got it. You are using the Code control as a code snippet (no code execution) in your custom element without any `<script>` tag.

In that case the syntax highlighter doesn’t work. As the JS code needs to be wrapped in a script tag. So we’ll include the JavaScript highlighter in 1.4 (stable release). Then you just need to set `mode: 'javascript'` in your custom element PHP class, and the syntax highlighter should kick in.

For anyone else reading this in the future:  
In 1.4 setting the “Language” in the Code element to `css`, `javascript`, or `php` will enable the syntax highlighter for those languages as well inside the code editor in the panel (Code execution disabled):

 ![bricks-code-element-snippet-set-language](https://forum.bricksbuilder.io/uploads/default/original/2X/6/647709c752dd892e9d414a6c755029774bd89108.png)

---

<div class="post-metadata">

**Author:** ![wolfgang](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/wolfgang/32/26083_2.png) [@wolfgang](https://forum.bricksbuilder.io/u/wolfgang)\
**Post date:** [May 9, 2022, 1:28pm UTC](https://forum.bricksbuilder.io/t/solved-setting-mode-in-code-control-no-syntax-highlighter/2739/7 "2022-05-09T13:28:31Z")

</div>

Hey Thomas,

yeah you almost nailed it. I am also executing that code but I create the tag inside the render function. That’s why I wanted to change the mode to ‘javascript’ to have seperated input areas for all different languages! 😉

Cool, sounds perfect for me, looking forward for 1.4 → thanks for the information!
