Skip to content
Treatlly
CMS & Website Builder

Theme Code: a guide for web developers

How a web developer can add and customise sections on a clinic website with Theme Code, while the clinic's team keeps editing everything by drag and drop.

Updated 5 days ago · 21 views

Theme Code is for the web developer a clinic hires. It lets you change your clinic's copy of its website design — the layout, the sections, the stylesheets and scripts — add files of your own, and upload images, fonts and short videos, while your staff keep editing every word, photo and link by drag and drop in the page builder.

You write a section once and describe its editable fields. From then on the clinic's team fills those fields in the builder, so you are never called back to change a phone number.

Before you start

  • Theme Code appears under Website only when Treatlly has opened it for your clinic, and only for people who are allowed to manage the website. Treatlly switches this on for your clinic — ask support if you don't see it.
  • You need to be comfortable with HTML, CSS and Liquid templates.
  • If you are the clinic's own admin and not a developer, you probably want Editing pages with the drag-and-drop builder instead.

What you see in Theme Code

Open Website → Theme Code. The page is called Theme source and names your clinic's current design. The files of that design are listed on the left in four groups, and you can change every one of them.

GroupWhat is in it
Layoutlayout.liquid: the frame that wraps every page
Sectionssections/*.liquid: one file per section, the building blocks of a page — the design's own, the ready-made sections every design can use (FAQ, Photo gallery and Custom section, tagged platform) and any you add
AssetsThe design's stylesheets, scripts, images and fonts, plus anything you add or upload
Settingstheme.json: the design's settings

The editor colours HTML, CSS, JavaScript and Liquid, numbers the lines and lets you fold blocks. Shortcuts: Cmd/Ctrl+S save, Cmd/Ctrl+F find, Cmd/Ctrl+/ comment a line, Alt+↑/↓ move a line, Cmd/Ctrl+G go to a line.

Your changes belong to your clinic

Every clinic starts with the design's original files. The first time you save a file — or upload a replacement — your clinic gets its own copy of it, and only your clinic's website uses it. Other clinics that use the same design keep the original, and you never affect theirs. A file you changed is tagged edited; a file you added is tagged yours.

Your copies also belong to the design they were made for. If you switch your website to another design, they are put aside; switch back and they return.

Restore the original

Open a file tagged edited and press Restore original: your copy is removed and your website uses the design's file again. On a file tagged yours, the same place offers Delete file.

Design updates do not reach your copy. When Treatlly improves a design, a file you have your own copy of keeps your version. To take the improvement, restore the original and make your change again.

Change the layout

layout.liquid wraps every page, and you can change anything in it. Your copy must keep these three lines, or it is not saved:

  • {{ content_for_layout }} — where each page's sections appear.
  • {{ theme.head_code_snippet }} — your search-engine, analytics and app tags, inside <head>.
  • {{ csrf_token }} — keeps the booking and sign-in forms working, in <meta name="csrf-token" content="{{ csrf_token }}">.

A layout or section with a Liquid mistake, for example an {% if %} without its {% endif %}, is not saved, and the message says what is wrong — so a typing slip never takes your website down.

Stylesheets, scripts, images, fonts and videos

  • Change the design's stylesheet or script: open it under Assets, edit it and press Save.
  • Add your own stylesheet or script: under New stylesheet or script, type a name, choose CSS or JS and press Create file. The new file starts with the exact line to paste into your layout: a stylesheet goes inside <head>, a script just before </body>. A few names are kept for the platform's own files; the editor tells you if you pick one.
  • Upload images, fonts and videos: under Upload fonts, images or videos, choose one or more files and press Upload to my assets. Images: PNG, JPG, WebP or GIF, up to 5 MB. Fonts: OTF, TTF, WOFF or WOFF2, up to 5 MB; they go in assets/fonts/. Videos: MP4 or WebM, up to 8 MB — patients often open your site on mobile data, so keep videos short. Every file is checked by its content, not by its name.
  • Replace one of the design's images or fonts: open it under Assets and use Replace for my clinic, or upload a file with exactly the same name.
  • Use a file: {{ 'clinic-photo.jpg' | asset_url }} gives its address. In a stylesheet in assets/, url("clinic-photo.jpg") works too, and a font is url("fonts/brand-font.woff2"). After each save the address from asset_url changes slightly, so visitors get the new file straight away.

Create a new section

  1. Go to Website → Theme Code.
  2. In the file list, find the Add section form under the Sections group.
  3. Type a Handle, for example clinic_timings. Use lowercase letters, numbers, dashes and underscores; capitals are lowercased and spaces become dashes.
  4. Optionally type a Label.
  5. Press Create section file.

Treatlly creates sections/<handle>.liquid with a small starter section and confirms that it was added to the builder palette. From then on it appears automatically in the page builder's Add new section list, ready to drag onto any page. If the handle already exists you are told so and nothing is overwritten.

Choose your own names for new sections. To change the FAQ, Photo gallery or Custom section for your clinic, open its file under Sections and edit it — that makes your clinic's own copy. A new section needs a handle of its own, for example clinic_timings; a handle that already exists is refused. A section with its own name appears in the builder alongside the ready-made ones.

The starter has no editable fields yet. Until you add a schema with at least one setting (next section), the builder shows only a generic content box that your template does not read.

Describe the editable fields: the schema block

At the bottom of a section file, a {% schema %} block written in JSON tells the builder what to show. The worked example below has a complete one. It has three parts.

  • name: how the section is labelled in the builder.
  • settings: the fields for the whole section. Each one has a type, a label and, ideally, a default. It may also have help_text (small print under the field), placeholder and rows.
  • blocks: repeatable rows, such as one per service or per timing. Each block type has a name, an optional limit (the most rows allowed) and its own settings.

A list form also works if you prefer it: put an id on each setting and a type on each block.

Field types the builder shows

TypeWhat the clinic sees
stringA single-line box. Any type the builder does not recognise is shown this way too.
textA multi-line box.
htmlA multi-line box in a code font.
integer, float, decimalA number box.
booleanA tick box.
imageA file upload. JPEG, PNG, GIF, WebP or AVIF, up to 10 MB.
videoA file upload for MP4 or WebM, up to 8 MB. Section settings only.

To turn a setting into a dropdown, add an options list. The dropdown also offers an empty choice.

"alignment": {
  "type": "string",
  "label": "Alignment",
  "default": "left",
  "options": [
    { "value": "left",   "label": "Left" },
    { "value": "centre", "label": "Centre" }
  ]
}

To list the clinic's own menus in a dropdown, add "options_source": "navigations" to the setting instead of options.

Inside blocks the builder offers a single-line box, a multi-line box (text) and an image upload. Everything else in a block appears as a single-line box, and blocks have no dropdowns or tick boxes. Each block row has up and down arrows and a Remove button, and the section's panel offers an Add button named after your block.

What the builder does with your schema

  • Only declared settings are kept. A value your Liquid reads but your schema does not declare is dropped the next time someone saves the section in the builder.
  • Declare at least one setting, or the builder does not show your fields (or your block rows) at all.
  • Four colour pickers are added to every section automatically — Background color, Text color, Heading color and Link color, in a Colors area at the bottom of the panel. There is no need to declare them.
  • A setting's default is used until the clinic sets a value. A block's default pre-fills a newly added row only, so in the Liquid still write | default: for anything that could be empty.
  • The schema must be valid JSON. A section whose schema is not valid JSON is not saved, and the message shows where the JSON breaks.

Read the values in Liquid

  • section.settings.<id>: a section-level value.
  • section.blocks: loop over it, and read block.settings.<id> for each row. block.type is the block type.
  • section.id: a unique id for this copy of the section. Use it in your wrapper's id so two copies on one page do not clash.
  • Images: read the web address from section.settings.<id>_url (or block.settings.<id>_url for a block). It is empty until a photo is uploaded, so wrap it in an {% if %}.

Anything a person types must go through escape. For multi-line text use escape | newline_to_br, in that order.

Clinic data your section can print

These are available in every section.

NameWhat you can read
tenanttenant.name (the clinic name), tenant.legal_name, tenant.logo_url and tenant.favicon_url.
doctorsThe clinic's doctors, in the order set under Doctors. For each: name, slug, specialization, department, qualification, photo_url, bio, expertise, languages, registration_number, registration_council, availability (true when the doctor is taking appointments) and verified (true when the name should be shown with “Dr.”).
navigationsThe clinic's menus. navigations.by_name["Main menu"].links gives that menu's links, each with label and url. Use the menu name exactly as it appears under Website → Navigation.
{% for doctor in doctors %}
  <h3>{% if doctor.verified %}Dr. {% endif %}{{ doctor.name | escape }}</h3>
  <p>{{ doctor.specialization | escape }}</p>
  <a href="/doctors/{{ doctor.slug }}">Book now</a>
{% endfor %}

A doctor's own page is at /doctors/ followed by the doctor's slug.

The clinic's phone number, email and address are not available as global values. Make them settings on your section so the team can edit them in the builder.

Filters worth knowing

FilterUse it for
escapeEvery piece of text a person typed.
safe_urlEvery link or web address a person typed, in an href or src.
asset_urlThe design's own images and files, for example {{ 'file-name.png' | asset_url }}. Photos your clinic uploads come through image settings instead.
css_colorA colour a person typed, before you print it into your own CSS.
video_embed_srcA YouTube link a person pasted. It gives you the address to put in an iframe, or nothing if the link is not from a supported video site.

A worked example: Clinic timings

This section has a heading, a note and an optional button, plus up to eight timing rows the team can add, reorder and remove. Paste it into a new section file (see above), press Save, then add Clinic timings to a page in the builder.

{% comment %} Clinic timings: one row per group of days {% endcomment %}
<section class="ct-timings" id="section-{{ section.id }}">
  <div class="ct-wrap">
    {% if section.settings.heading != blank %}
      <h2 class="ct-heading">{{ section.settings.heading | escape }}</h2>
    {% endif %}
    {% if section.settings.note != blank %}
      <p class="ct-note">{{ section.settings.note | escape | newline_to_br }}</p>
    {% endif %}

    <ul class="ct-list">
      {% for row in section.blocks %}
        <li class="ct-row">
          <span class="ct-days">{{ row.settings.days | default: "Mon to Sat" | escape }}</span>
          <span class="ct-hours">{{ row.settings.hours | escape }}</span>
        </li>
      {% endfor %}
    </ul>

    {% if section.settings.button_link != blank %}
      <a class="ct-button" href="{{ section.settings.button_link | safe_url }}">
        {{ section.settings.button_text | default: "Book an appointment" | escape }}
      </a>
    {% endif %}
  </div>
</section>

<style>
  #section-{{ section.id }} .ct-wrap { max-width: 40rem; margin: 0 auto; padding: 3rem 1rem; }
  #section-{{ section.id }} .ct-list { list-style: none; margin: 1.5rem 0; padding: 0; }
  #section-{{ section.id }} .ct-row { display: flex; justify-content: space-between; gap: 1rem; padding: .75rem 0; border-bottom: 1px solid rgba(0,0,0,.1); }
  #section-{{ section.id }} .ct-button { display: inline-block; padding: .75rem 1.25rem; border-radius: .5rem; background: #0f766e; color: #fff; text-decoration: none; }
</style>

{% schema %}
{
  "name": "Clinic timings",
  "settings": {
    "heading":     { "type": "string", "label": "Heading", "default": "Clinic timings" },
    "note":        { "type": "text",   "label": "Note under the heading", "default": "", "help_text": "For example: closed on public holidays." },
    "button_text": { "type": "string", "label": "Button text", "default": "Book an appointment" },
    "button_link": { "type": "string", "label": "Button link", "default": "", "help_text": "Leave empty to hide the button." }
  },
  "blocks": {
    "timing": {
      "name": "Timing row",
      "limit": 8,
      "settings": {
        "days":  { "type": "string", "label": "Days",  "default": "Mon to Sat" },
        "hours": { "type": "string", "label": "Hours", "default": "10:00 am to 6:00 pm" }
      }
    }
  }
}
{% endschema %}

Rules that keep drag-and-drop working

  • One section per file, with one outer wrapper element.
  • Never put a {% section %} tag inside a section. Sections are placed by the builder, not by each other.
  • Every editable text, image and link is a schema setting. Do not hard-code clinic content such as a phone number into the markup.
  • Give every setting a sensible default, so a freshly added section looks right before anyone edits it.
  • Keep the section self-contained: its own wrapper and its own styles.
  • Use plain headings, paragraphs, list items and links. The four colour pickers colour these tags inside your section. If your own CSS sets a colour on them with a class, your colour wins over the picker, so leave colour to the pickers where you can. A link whose class contains button is treated as a button and is not recoloured by the Link color picker.

Styling your section

The shared utility stylesheet is built from the sections that ship with the design, so a utility class is only available if one of those sections already uses it. For anything else, write your own CSS:

  • reuse classes you can see in the design's own sections, or
  • add rules to your copy of the design's stylesheet, or to a stylesheet of your own (see above), or
  • write a <style> block inside the section, with your own class prefix (the example uses ct-) and scoped under #section-{{ section.id }}.

Test, back up and undo

  1. Add the section to a page in the builder and check it in the builder preview before you save the page. View published page opens the live result.
  2. Press Save in Theme Code after every change. A confirmation says the file was saved as your clinic's own copy.
  3. Keep your own copy of every file you write or upload. The website backup and the setup backup save your pages, menus, the design's settings and each section's settings — but not your Theme Code files: the layout, sections, stylesheets, scripts and uploads.

Undoing a change. Restore original undoes all your changes to one file at once. In the builder, Reset on a section puts that section's settings back to the design's defaults; it does not touch your code. To go back to an earlier version of your own code, paste your saved copy back into the file and press Save.

theme.json. The builder updates this file as people edit pages. Leave it to the builder unless you know exactly what you are changing. It must stay a valid JSON object; if it is not, you are told and nothing is saved.

If something looks wrong

What you seeWhat to check
The section is not in Add new sectionYou are on a different design from the one you wrote it for. Switch back and it returns.
The builder shows no fieldsThe schema declares no settings, or its JSON is invalid.
A value disappears after the team edits itThe setting is read in Liquid but is not declared in the schema.
A photo does not showRead <id>_url, not <id>, and check it is not empty.
Your layout is not savedIt must keep the three lines listed under Change the layout, and every Liquid tag must be complete. The message names what is missing.
A visitor still sees a design image you replacedAn image named in a stylesheet (url(…)) can stay in a visitor's browser for up to an hour after you first replace it. Files linked with asset_url update at once.
An upload is refusedCheck the file type and size above. A file renamed to look like an image or video is refused.

See Editing pages with the drag-and-drop builder for the builder itself, and see Building your clinic website.

Was this helpful?
Share:

Still need help?

If this article didn't answer your question, our support team is ready to assist.

Request More Help