Preview Mode
The preview mode functionality allows content editors to preview Prismic content changes before publishing them to the live site.
Components
PreviewMode Block
The PreviewMode block handles the integration of Prismic's preview script and is automatically added to pages when preview mode is enabled.
Preview Controller
Handles preview requests and redirects to the appropriate page.
Configuration
Preview mode can be enabled in the Magento admin:
Implementation
Preview Script Integration
The module automatically adds the Prismic preview script to your pages when preview is enabled:
Preview Flow
- Editor clicks preview in Prismic
- Request is sent to
/prismicio/preview/index
- PreviewController validates the token
- Controller resolves the document URL
- User is redirected to the preview page
Security Considerations
The preview controller: - Only works when preview mode is enabled - Validates preview tokens - Falls back to 404 for invalid requests
Template Integration
<referenceBlock name="before.body.end">
<block ifconfig="prismicio/content/allow_preview"
name="prismicio_preview_html"
class="Elgentos\PrismicIO\Block\PreviewMode"
template="Elgentos_PrismicIO::preview-mode.phtml" />
</referenceBlock>
API Methods
PreviewMode Block
public function getApiEndpoint(): string
public function getRepoName(): string
public function getPreviewUrl(): string
Preview Controller
Best Practices
- Security
- Only enable preview in necessary environments
- Use HTTPS for preview requests
-
Implement proper access controls
-
Performance
- Preview script is only loaded when preview is enabled
- Preview requests are not cached
-
Preview mode is disabled by default
-
Implementation
- Use proper preview URLs in Prismic configuration
- Handle preview timeouts appropriately
- Consider preview in multi-store setups
Troubleshooting
Common issues and solutions:
- Preview Not Working
- Verify preview mode is enabled
- Check preview URL configuration in Prismic
-
Validate preview token handling
-
Preview Script Issues
- Check CSP configuration
- Verify repository name resolution
-
Monitor browser console for errors
-
Preview Routing
- Verify LinkResolver configuration
- Check store-specific preview handling
- Review preview URL generation