Understanding Fields
Fields bridge the gap between code and content:- Component code defines structure and styling
- Fields define what content editors can edit
- Together they create blocks that are both powerful and editable
Fields can be added to both blocks (for component-level editing) and page types (for page-level metadata). The process is the same for both.
Adding Fields to a Block
1
Create or open your component
In the Component Library, create a new block or open an existing one.
2
Write your component code
Build your component. Fields are globally available—no need to declare them:
3
Open the field editor
Click “Add Field” or the fields panel in the component editor.
4
Create your first field
Configure the field:
- Field name: Must match your prop name (e.g.,
headline) - Field type: Choose the appropriate type (e.g., Text, Rich Text, Image)
- Label: Display name for editors (e.g., “Headline”)
- Default value: Optional pre-filled value
The field name must exactly match the prop name in your component code.
5
Add more fields
Repeat for each prop you want to make editable:
description→ Rich Text fieldimage→ Image field
You don’t need to create fields for every prop. Only create fields for content you want editors to control.
6
Save your block
Click “Save Block” to save your component with its fields.
Field Naming
When you create a field, the field name determines how you reference it in your component:- Field name:
cta_text(how you reference it in code) - Label: “CTA Text” (what editors see in the UI)
Common Field Patterns
Hero Block
A typical hero block might use these fields in the template:headline(Text) - Main headlinesubheadline(Text) - Supporting textcta_link(Link) - Button link with labelbackground_image(Image, optional) - Background image
Text Block
A simple text block:content(Rich Text) - The main contentalignment(Select) - Options: “left”, “center”, “right”
Image Block
An image with caption:image(Image) - The image (includes URL and alt text)caption(Text, optional) - Image caption
Card Grid Block
A grid of cards using a repeater:cards(Repeater) with nested fields:title(Text)description(Text)image(Image, optional)link(Link, optional)
columns(Number) - Number of columns
Template Syntax Guide
Pala blocks use Svelte 5 syntax. Here’s the essential syntax you’ll use most often when working with fields.Basic Interpolation
Display field values in your template:Fallback Values
Provide default values when fields are empty:Conditionals
Show or hide elements based on field values:Loops (Repeater Fields)
Iterate over repeater field arrays:HTML Rendering
Render HTML from rich text or markdown fields:Rich text and markdown fields render HTML using
{@html}. Since content comes from trusted editors (not site visitors), this is safe to use.Reactive Statements
Compute derived values from fields:Event Handlers
Handle user interactions:Class Directives
Apply classes conditionally:Style Directives
Apply inline styles dynamically:Snippets (Reusable Templates)
Create reusable template chunks within a block:What You Won’t Need
These Svelte features are not relevant for Pala blocks:- Stores - No need for cross-component state; fields are globally available within each block
- Context API - Use relational fields instead (Page Field, Site Field, Page, Page List) to reference data from elsewhere
- $bindable - Only for component authoring, not block templates
- Custom elements - Blocks compile to standard components
- SvelteKit features - Routing, load functions, etc. (Pala handles this)
- Component slots - Blocks don’t accept slotted content
Learn More
For advanced Svelte features and patterns, see the Svelte 5 documentation.Field Configuration
Required Fields
Mark fields as required when they’re essential:A Hero block’s
headline field should be required—a hero without a headline doesn’t make sense.- Essential content (headlines, titles)
- Fields that affect functionality
- Fields needed for proper display
- Optional enhancements (images, captions)
- Fields with sensible defaults
- Decorative elements
Default Values
You can set default values in the field configuration, or handle empty values in your template:- Set sensible defaults in field configuration
- Handle empty/missing values gracefully
- Make components functional even with minimal content
Help Text
Add help text to guide editors:Field:
background_image
Help text: “Optional background image. Recommended size: 1920x1080px. Will be used as a fallback if no image is provided.”- Explains what the field is for
- Provides guidance on content
- Mentions any requirements (size, format, etc.)
Placeholders
Use placeholders to show example content:- Headline field: “Enter your headline here”
- Description field: “Describe your product or service”
- Link field: “/about” or “https://example.com”
Advanced Field Patterns
Conditional Fields
Conditional Fields
Conditional Fields
Some fields should only appear when others have values:Setting up conditionals:- Create the control field (e.g.,
video_type) - Configure dependent fields to show/hide based on the control field
- Test with different values
Repeater Fields
Repeater Fields
Repeater Fields
Repeaters let editors add multiple items:1
Create the repeater field
Add a Repeater field (e.g.,
features).2
Add nested fields
Inside the repeater, add fields for each item:
title(Text)description(Text)icon(Image, optional)
3
Use in component
Reference the repeater field as an array:
Group Fields
Group Fields
Group Fields
Groups organize related fields:1
Create a group field
Add a Group field (e.g.,
author).2
Add fields to the group
Inside the group, add related fields:
name(Text)email(Email)bio(Textarea)
3
Use in component
Reference the group field as an object:
Field Validation
Text Validation
Add validation rules to text fields:- Min length: Minimum character count
- Max length: Maximum character count
- Pattern: Regex pattern for format validation
An email field might use pattern:
^[^\s@]+@[^\s@]+\.[^\s@]+$Number Validation
For number fields:- Min value: Minimum allowed number
- Max value: Maximum allowed number
- Step: Increment/decrement step
A “Price” field might have:
- Min: 0
- Max: 10000
- Step: 0.01 (for cents)
File Validation
For image and file fields:- Allowed formats: File extensions (jpg, png, pdf, etc.)
- Max file size: Maximum upload size in MB
- Dimensions: Min/max width and height (for images)
Testing Fields
Test with Empty Values
Always test your components with empty fields:Test with Default Values
Verify defaults work (if you set them in field configuration):- Create a page with your block
- Don’t fill in any fields
- Check that the component displays correctly with default values
Test Edge Cases
Try:- Very long text
- Special characters
- Empty arrays (for repeaters)
- Missing nested fields (for groups)
Best Practices
1. Start Simple
Begin with essential fields, add more as needed:2. Use Descriptive Labels
Labels are what editors see:- ✅ “Featured Image”
- ✅ “Publication Date”
- ✅ “Author Name”
- ❌ “Field 1”
- ❌ “Data”
3. Provide Helpful Defaults
Set defaults in field configuration to make components work immediately:- Number fields: Set sensible defaults (e.g.,
columnsdefaults to 3) - Boolean fields: Set appropriate defaults (e.g.,
show_titledefaults to true) - Select fields: Pre-select the most common option (e.g.,
alignmentdefaults to “left”)
4. Group Related Fields
Use Groups or organize fields logically:- Content fields: headline, description, content
- Media fields: image, video, background
- Settings fields: alignment, columns, variant
5. Validate Input
Add validation to prevent errors:- Required fields for essential content
- Format validation for emails, URLs
- Size limits for files and text