Content Types
Content types in Prismic define the structure of your content. They are like templates that specify which fields are available for your content editors. In the Magento-Prismic integration, content types are used to organize and display different kinds of content.
Understanding Content Types
A content type in Prismic might include: - Basic fields (Text, Number, Boolean, etc.) - Rich Text fields for formatted content - Link fields for internal/external links - Media fields for images and other assets - Slices for flexible content blocks - Integration fields for Magento product data
Setting Up Content Types in Prismic
- Go to your Prismic dashboard
- Navigate to Custom Types
- Click "Create new"
- Choose between Repeatable Type or Single Type:
- Repeatable Type: For content that can have multiple instances (e.g., blog posts, products)
- Single Type: For unique content (e.g., homepage, about page)
- Define your fields:
Configuring Content Types in Magento
Default Content Type
Set your default content type in Magento admin: 1. Go to Stores > Configuration > Elgentos > Prismic.IO 2. Under Content Settings, select your "Default Content Type" 3. This will be used when no specific content type is specified
Layout-Specific Content Types
You can specify different content types for different layouts:
<block class="Elgentos\PrismicIO\Block\Template" name="prismic.content">
<arguments>
<argument name="content_type" xsi:type="string">blog_post</argument>
</arguments>
</block>
Best Practices
- Naming Conventions
- Use clear, descriptive names
- Follow a consistent pattern (e.g.,
page_
,blog_
,product_
) -
Avoid spaces and special characters
-
Field Organization
- Group related fields together
- Use tabs for better organization
-
Consider the editing experience
-
Integration Fields
- Use Integration Fields for Magento product data
- Configure which product attributes to expose
-
Consider performance implications
-
Content Type Planning
Technical Implementation
Fetching Content by Type
// In your block class
public function getContent()
{
$contentType = $this->getContentType() ?? 'default_type';
$api = $this->getPrismicApi();
return $api->query([
Predicates::at('document.type', $contentType)
]);
}
Content Type-Specific Templates
<!-- Layout XML -->
<block class="Elgentos\PrismicIO\Block\Template" name="prismic.content">
<arguments>
<argument name="content_type" xsi:type="string">blog_post</argument>
<argument name="template" xsi:type="string">prismic/content/blog-post.phtml</argument>
</arguments>
</block>
Common Content Types
- Pages
- Homepage
- About page
- Contact page
-
Landing pages
-
Marketing Content
- Banners
- Promotions
-
Campaign pages
-
Blog/News
- Blog posts
- News articles
-
Press releases
-
Product Enhancement
- Extended descriptions
- Usage guides
- Product stories
Troubleshooting
- Content Not Displaying: Verify content type name matches exactly
- URL Rewrites Not Generating: Check webhook configuration
- Integration Fields Not Working: Verify product attribute configuration
- Preview Not Working: Ensure preview mode is enabled for content type