Components vs Blocks
Understanding the distinction helps you build better: Components are pure Svelte code:- Reusable UI elements (Button, Card, Hero)
- Accept props and handle logic
- No content fields attached
- Can be used anywhere in your Svelte code
- Same Svelte component code
- Plus editable content fields (text, images, links)
- Used specifically in page types and pages
- Editors can modify content, not code
When you create a block in Primo, you’re writing a Svelte component and then attaching fields to it. The component code stays the same; fields make it editable.
Component Structure
Every Primo component follows this structure:Writing Your First Component
Let’s build a simple Button component step by step:1
Identify the fields you need
Think about what data your component needs. For a button block:
text: The button texthref: The link destinationvariant: The button style (primary, secondary, outline)
2
Add the markup
Write the HTML structure:
3
Style the component
Add scoped styles:
Best Practices
1. Handle Empty Values
Components should work gracefully even with empty fields:2. Use Conditional Rendering
Only show elements when content exists:3. Handle Arrays Safely
When working with repeater fields, always check if the array has items:4. Use Scoped Styles
Primo components use scoped styles by default. Use:global() when you need to style child elements:
5. Make Components Responsive
Always consider mobile devices:6. Create Component Variations
Instead of creating many similar blocks, use fields to create variations of a single component: Layout variations:Working with Rich Content
Rich Text Fields
When using rich text fields, use{@html} to render HTML:
Markdown Content
If you’re using markdown fields, Primo processes them automatically. But you can also use a markdown processor for additional control:Advanced Patterns
Reactive Statements
Use reactive statements ($:) for computed values based on fields:
Event Handling
Handle user interactions:Conditional Classes
Use dynamic classes for variants:Component Composition
Build complex components from simpler ones:In Primo’s component editor, you write single-file components. For composition, you can create separate blocks and reference them, or write everything in one component file.
Performance Considerations
Lazy Loading Images
For image-heavy components:Optimize Re-renders
Use reactive statements efficiently:Testing Your Components
Use the Preview
Primo’s in-browser editor provides instant preview:- Write your component code
- Add test content in fields
- See changes update in real-time
Test Different Screen Sizes
Use browser dev tools in the preview to test:- Mobile (320px - 768px)
- Tablet (768px - 1024px)
- Desktop (1024px+)
Common Patterns
Next Steps
Working with Fields
Learn how to attach content fields to your components.
Using the Component Library
Organize and reuse components across sites.
Field Types Reference
Complete reference of all available field types.
Your First Site
See components in action with a complete site example.