Components
Components are the building blocks of primo sites. They're totally self-contained (unless there's a style or field they share with other components).
Creating a Component
Focus on a row on the page
Click 'Component' in the toolbar
Write code under the 'Code' tab, create fields under the 'Fields' tab
Component Code
HTML
See an instant preview of what your code looks like
Use [Handlebars](https://handlebarsjs.com/) to wire up your fields
Use [Emmet](https://docs.emmet.io/abbreviations/syntax/) to quickly write HTML (e.g.
div>div>h1.heading
and press Tab)
CSS
Styles are encapsulated (so if you only have one image tag in your component, you can safely select it with
img.
Nested styles are supported (using [postcss-nested](https://github.com/postcss/postcss-nested))
JavaScript
You can import any JS modules by name with
import module from 'module-name'
, wheremodule-name
is the module's name on [npm](https://www.npmjs.com/). In the background, primo turns that into a request to [Skypack](https://skypack.dev/) that looks likeimport module from 'https://cdn.skypack.dev/module-name'.
Skypack is a CDN that sends visitors pre-optimized packages.Additional values related to the component can be found under a variable named
primo
.primo
contains three properties:id
is the component's unique ID. Typically used to select the component's node.data
contains the component's field valuesfields
contains the component's fields
Sometimes you'll need to call a function from your HTML
To do so, you'll need to define the function globally from the component's JS
To avoid overwriting a global function (especially when reusing a component), create a global namespace using the component's ID.
And access it from the component's HTML
Component fields
Fields let you easily change content inside HTML from the CMS side.
Create a field
From within the Component Editor, click the Fields tab
Add a field, selecting a field type based on the data type
Repeater: Lists
Group: Objects
Content: Markdown
Switch: Boolean
Text, Number, URL
Give the new field a label and an ID
Label: Labels the input field in the CMS
ID: Used from within the component's HTML to access the field value
Connect field to HTML
primo uses the [Handlebars](https://handlebarsjs.com/) compiler to build HTML from field values. Once you create a field, you can access their values from within the component HTML using the field's ID.
Some handlebars features like partials aren't supported yet
Last updated