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
Write your component code
Build your component. Fields are globally available—no need to declare them:
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.
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.
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:Group Fields
Group Fields
Group Fields
Groups organize related fields: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
Common Mistakes
Mismatched Names
Field names must match how you reference them in code:Not Handling Empty Values
Always handle missing or empty field values:Over-Complicating
Start simple, add complexity later:Next Steps
Field Types Reference
Complete reference of all available field types.
Writing Components
Learn how to write components that work well with fields.
Building from Scratch
See fields in action with a complete site example.
Defining Page Types
Add page-level fields to page types.