Skip to Content
AppearanceStudio

Code in Studio

How to add CSS to one block, change the HTML template of every block of a type, rearrange the site frame and run your own JavaScript.

When the look settings fall short, Studio lets you write code: CSS for one block, your own HTML template for every block of a type, the site frame template and a script that runs on every page. By the end of this page you will know where each of these layers lives, who can use it and why code may refuse to save.

All code goes to the draft and reaches the site when you publish, like any other edit. "Undo" or "Versions" roll it back.

WhatWherePermission
CSS of one blockblock → "Look" → "Custom CSS""Custom CSS" (sections.css)
Template and styles of a block typeblock → "Code""Custom CSS" (sections.css)
Site template"Whole site" → "For developers" → "Site template"sections.css and sections.theme
Site scripts"Whole site" → "For developers" → "Site scripts"admin.boss
The "HTML code" blockblock list, "More blocks" groupadmin.boss

CSS of one block

Select a block, open the "Look" tab and its "Custom CSS" section. Put space-separated classes in "CSS classes" and the rules in "CSS of this block". & stands for the block root, and a selector without & matches inside the block:

CSS of this block
& { border-top: 2px solid var(--accent); }
h2 { letter-spacing: 0.02em; }

The rules apply to this block only. A duplicate gets the same rules, applied to itself. Take colours from the theme variables (var(--accent)) so the block looks right in both the light and dark scheme. One block takes up to 4096 characters.

The CSS contains forbidden constructs (url, @import, expression and the like)

External addresses in url(), @import, expression() and behavior are refused in block CSS, because this code runs for every visitor. Upload a background picture in the block settings instead.

Template of a whole block type

A block's "Code" tab shows its "HTML template" and "Styles". An edit here "Changes how every «…» block on the site looks", so every "Questions and answers" block on every page. To change only some of them, click "Save as variant…": the new variant appears under "Look" → "Variant" and can be switched on for the blocks you choose.

Code tab: HTML template, styles, the Block data list and Must stay in the template

The template has the block's data, and the "Block data" list inserts it on click:

SyntaxWhat it prints
{{title}}the field value, escaped
{{#items}}…{{/items}}a repeat for each list item, or once if the field is set
{{^items}}…{{/items}}shown when the field is empty
{{&part}}a ready part of the block from the list, in text only

Parts listed under "Must stay in the template" can't be removed, the block doesn't work without them. <script> and handlers like onclick are stripped; live updates and tabs have ready attributes: data-lx-live="30s", data-lx-toggle with data-lx-target, data-lx-tabs, data-lx-carousel. "Reset to standard" returns the template and styles to the theme's version.

"Own look from scratch" → "Drop the standard look" renames the fs-… classes in the template and styles, after which only your styles apply.

The rows for {{#items}} can come from a module's data source. How a module adds its own source is covered in What modules and themes add to Studio.

Site template

"Site template" on the "Whole site: header, footer, code" tab arranges the header, navigation, content and footer on every page. It is there when the theme supports it. Next to the editor are the "Theme parts" (required ones are marked) and "Block zones", placed with {{&part}}, each once.

Site template editor with the Theme parts and Block zones lists

Template styles apply inside the page: start a rule with &, not html or body. Parts that sit side by side need an @media rule for phones, otherwise Studio warns "Parts sit side by side with no @media rule: they will not fit a phone screen". "Reset to theme" brings back the theme's layout.

If a published template starts breaking pages, the site puts the previous one back and says "The site template was rolled back: …". The draft is kept, so fix it and publish again.

Site scripts

"Site scripts" is JavaScript that runs on every page. In the editor it runs in the draft only, and visitors get it once you publish. The site moves between pages without a full reload, so wrap your code in flute.site.ready: the function runs right away and after every page change.

Site scripts
flute.site.ready(function () {
  document.querySelectorAll('a[href^="https://discord.gg"]').forEach(function (a) {
    a.target = '_blank';
  });
});

document.write and </script are forbidden in the script, and it takes up to 64 KB.

Troubleshooting

For any other message, use the error lookup.

MessageWhat to do
"You do not have the right to change block CSS"the role lacks sections.css
"The CSS has an unclosed bracket or quote"check that {} and quotes come in pairs
"The block CSS is too long"over 4096 characters: move shared rules into the block type template
"The template must keep the required hooks: …"put back the parts from "Must stay in the template"
"The variant is used on: …"switch those blocks to another variant, then delete it
"The current theme does not support a site template"the theme has no frame for it, edit the header and footer with blocks
"The styles hide the page content (#main), so they are not saved"remove the rule that hides #main

More

On this page