.. include:: /Includes.rst.txt .. _examples-template-overrides: ================== Template Overrides ================== .. versionadded:: 13.1.5 The new Fluid-based rendering architecture allows complete customization of image output via template overrides. Override the default Fluid templates to customize image rendering output for your site's design requirements. .. contents:: Table of contents :depth: 2 :local: Overview ======== The extension provides six Fluid templates for different rendering contexts: .. code-block:: text :caption: Template directory structure Resources/Private/Templates/Image/ ├── Standalone.html # Basic image without wrapper ├── WithCaption.html # Image with
/
├── Link.html # Image wrapped in tag ├── LinkWithCaption.html # Linked image with caption ├── Popup.html # Image with lightbox/popup link └── PopupWithCaption.html # Popup image with caption Template selection ------------------ The :php:`ImageRenderingService` automatically selects the appropriate template: .. list-table:: Template selection matrix :header-rows: 1 :widths: 50 50 * - Condition - Template * - No link, no caption - :file:`Standalone.html` * - No link, has caption - :file:`WithCaption.html` * - Has link, no popup, no caption - :file:`Link.html` * - Has link, no popup, has caption - :file:`LinkWithCaption.html` * - Has popup, no caption - :file:`Popup.html` * - Has popup, has caption - :file:`PopupWithCaption.html` Setting up overrides ==================== Step 1: Create template directory --------------------------------- In your site package, create the override directory: .. code-block:: bash :caption: Create template override directory mkdir -p packages/my_sitepackage/Resources/Private/Templates/Image/ Step 2: Configure TypoScript ---------------------------- Add the template path to your TypoScript setup: .. code-block:: typoscript :caption: EXT:my_sitepackage/Configuration/TypoScript/setup.typoscript lib.parseFunc_RTE { # Add your templates with higher priority (lower number = higher priority) settings.templateRootPaths { 10 = EXT:my_sitepackage/Resources/Private/Templates/ } } Step 3: Create override templates --------------------------------- Copy and modify only the templates you need to customize. Available DTO properties ======================== All templates receive the `image` variable containing an :php:`ImageRenderingDto`: .. code-block:: html :caption: Available template variables {image.src} {image.width} {image.height} {image.alt} {image.title} {image.caption} {image.isMagicImage} {image.htmlAttributes.class} {image.htmlAttributes.style} {image.htmlAttributes.loading} {image.link.url} {image.link.target} {image.link.class} {image.link.isPopup} See :ref:`api-imagerenderingdto` for complete property documentation. Example overrides ================= Bootstrap 5 responsive image ---------------------------- Override :file:`Standalone.html` for Bootstrap 5 responsive images: .. code-block:: html :caption: EXT:my_sitepackage/Resources/Private/Templates/Image/Standalone.html {image.alt} Figure with custom styling -------------------------- Override :file:`WithCaption.html` for custom figure styling: .. code-block:: html :caption: EXT:my_sitepackage/Resources/Private/Templates/Image/WithCaption.html
{image.alt}
{image.caption}
PhotoSwipe lightbox integration ------------------------------- Override :file:`Popup.html` for PhotoSwipe v5 integration: .. code-block:: html :caption: EXT:my_sitepackage/Resources/Private/Templates/Image/Popup.html
{image.alt} Lazy loading with placeholder ----------------------------- Override :file:`Standalone.html` for progressive image loading: .. code-block:: html :caption: Lazy loading with SVG placeholder {image.alt} Best practices ============== #. **Only override what you need**: Copy only templates requiring changes. #. **Preserve accessibility**: Always include `alt` attribute and maintain semantic HTML. #. **Keep security intact**: The DTO properties are pre-sanitized. Do not apply additional encoding that could double-escape content. #. **Test all contexts**: Verify overrides work with captions, links, and popups. #. **Use native lazy loading**: Prefer `loading="lazy"` over JavaScript solutions. Debugging templates =================== Enable Fluid debugging to inspect available variables: .. code-block:: html :caption: Debug all template variables {_all} Or in TypoScript: .. code-block:: typoscript :caption: Enable debug mode via TypoScript lib.parseFunc_RTE.settings.debug = 1 Related documentation ===================== - :ref:`api-imagerenderingservice` - Template selection logic. - :ref:`api-imagerenderingdto` - Available DTO properties. - :ref:`examples-image-styles` - CSS class configuration.