Start free

Section Template


Section templates are reusable page section components in Garchi CMS. They act as blueprints for sections on your pages.

To use a section template in your site, you need to have the corresponding component in your codebase. For example, a "Hero" template in Garchi CMS should have a (Hero.jsx) component in your React app or a "Card" template in Garchi CMS should have a (Card.vue) component in your Vue app.

To create a Section template

  1. Go to Structure ---> Section Templates in the dashboard sidebar.
  2. Click the "Add new template" button.
  3. Give the template a name that matches your component name.
  4. (Optional) Add a short description, such as the component's file path.
  5. (Optional) Fill in AI agent description for this section template: what the section is for and when to use it. AI agents connected to your space read it before they build pages.
  6. Click Save Changes.

Section template

You can edit the template by clicking Settings next to the respective template.

To delete a template click on the bin icon.

Adding Template Props

Props allow you to pass dynamic data to your section templates.

To add props to a template:

  1. Click "Content fields" on the respective Section Template.
  2. Click "Add field", enter a key for the prop and select the type: Short text, Long text, Rich text, Select, Media, Date, Lucid Icons or Hero Icons. For a Select, list the options separated by commas.
  3. Optionally, choose how editors fill the field with Show as (see below).
  4. Click the save icon on the row.

Show as: richer inputs without a new type

Some fields can be shown to editors as a more helpful control. The field keeps its type, and your frontend receives the same plain string as before, so no code or SDK changes are needed.

Field type Show as What editors see What your frontend receives
Short text Colour A colour picker with a box for any CSS colour The colour as entered, e.g. #CE2E22, rgb(206 46 34), hsl(4 71% 47%), tomato or var(--brand)
Short text Link A web address field, checked when saved The full URL, e.g. https://example.com/offer
Short text Number A number field, checked when saved The number as text, e.g. 12
Short text Yes/No toggle A switch true or false, as text
Short text Phone A phone number field, checked when saved The number as typed, e.g. +44 20 7946 0000
Select Colour palette Clickable colour swatches; the options must be CSS colours, e.g. #CE2E22,rgb(18 18 18),tomato The chosen colour
Select Multiple choice Tick boxes for several options The ticked options separated by commas, e.g. vegan,gluten-free
Select Buttons All options as a row of buttons, best for a few short ones like left,center,right The chosen option
Long text List A text box with one item per line The lines separated by new lines

Garchi checks values against the choice when content is saved from the dashboard or by an AI agent, so a colour field never ends up holding a word, and a multiple-choice field only holds options from your list. In your frontend, split a multiple-choice value on commas, read a toggle as a boolean, and split a list on new lines:

const diets = (props.diets || "").split(",").filter(Boolean);
const showBanner = props.show_banner === "true";
const features = (props.features || "").split("\n").map((line) => line.trim()).filter(Boolean);

Let's take an example of a React TeamCard component which has image, title and name

// TeamCard.jsx
function TeamCard({image, title, name})
{
    return (
    <div className="your_css_classes">
        <img src={image} alt={name} />
        <h2>{name}</h2>
        <p>{title}</p>
    </div>
    )
}

We also need to create the Section template named TeamCard through Garchi dashboard. After the section template is created through the dashboard, we need to add image, title and name as props.

After creating a "TeamCard" template, you can add those props value on the respective page through the dashboard so they can be populated dynamically.

For now the media type supports images only. You can manage the images by clicking on Content -> Assets.

Managing Section Templates via API

Utilize the section_template API to efficiently create or update Section Templates. This API requires a space_uid and a section_templates array, representing the component tree structure. Automating the creation of section templates through this API is more streamlined than the manual bulk operations available via the dashboard.

Each prop takes a key, a type, allowed_values for a select, and an optional show_as (the values in the Show as table above: colour, link, number, toggle, phone, palette, multiple, buttons or list). Leave show_as out to keep a prop's current setting.

The section_templates array facilitates the synchronization of the component tree within the specified space, allowing for the addition, update, or deletion of templates as necessary.

Example usage

Important: This method is recommended for development environments only.

Structure of components.json:

[
    {
        "name": "Header",
        "description": "A header section",
        "props": [
            {
                "key": "title",
                "type": "text"
            },
            {
                "key": "subtitle",
                "type": "text"
            }
        ]
    },
    {
        "name": "InputField",
        "prev_name": "FormField", //in case if updating an existing template
        "description": "A input field section",
        "props": [
            {
                "key": "label",
                "type": "text"
            },
            {
                "key": "placeholder",
                "type": "text"
            },
            {
                "key": "type",
                "type": "select",
                "allowed_values": "text,email,password",
                "show_as": "buttons" //optional, see Show as above
            }
        ]
    }
]

Sending a Request Using Node.js:

const components = require('./components.json')



fetch("https://garchi.co.uk/api/v2/section_template", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Accept": "application/json",
    "Authorization": "Bearer your_api_key",
  },
  body: JSON.stringify({
    "section_templates": components,
    "space_uid": "respective_space_uid"
  })
}).then(res => {
  if (res.ok) {
    return res.json()
  } else {
    return Promise.reject(res)
  }
})
.then(data => console.log(data))
.catch(err=> console.log(err))

Execution: Run this script as a one-off operation or continuously in development using tools like nodemon

node script.js

This approach ensures your Section Templates are seamlessly integrated and managed through your API, simplifying development workflows.