Skip to content

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

  1. Go to your Prismic dashboard
  2. Navigate to Custom Types
  3. Click "Create new"
  4. Choose between Repeatable Type or Single Type:
  5. Repeatable Type: For content that can have multiple instances (e.g., blog posts, products)
  6. Single Type: For unique content (e.g., homepage, about page)
  7. Define your fields:
    {
      "Main" : {
        "title" : {
          "type" : "Text",
          "config" : {
            "label" : "Title"
          }
        },
        "content" : {
          "type" : "StructuredText",
          "config" : {
            "label" : "Content"
          }
        },
        "featured_image" : {
          "type" : "Image",
          "config" : {
            "label" : "Featured Image"
          }
        }
      }
    }
    

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

  1. Naming Conventions
  2. Use clear, descriptive names
  3. Follow a consistent pattern (e.g., page_, blog_, product_)
  4. Avoid spaces and special characters

  5. Field Organization

  6. Group related fields together
  7. Use tabs for better organization
  8. Consider the editing experience

  9. Integration Fields

  10. Use Integration Fields for Magento product data
  11. Configure which product attributes to expose
  12. Consider performance implications

  13. Content Type Planning

    my_page/
    ├── Main
    │   ├── title (Text)
    │   ├── description (Rich Text)
    │   └── featured_image (Image)
    ├── SEO
    │   ├── meta_title (Text)
    │   ├── meta_description (Text)
    │   └── og_image (Image)
    └── Slices
        ├── text_block
        ├── image_gallery
        └── product_showcase
    

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

  1. Pages
  2. Homepage
  3. About page
  4. Contact page
  5. Landing pages

  6. Marketing Content

  7. Banners
  8. Promotions
  9. Campaign pages

  10. Blog/News

  11. Blog posts
  12. News articles
  13. Press releases

  14. Product Enhancement

  15. Extended descriptions
  16. Usage guides
  17. 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