|
| 1 | +.. include:: /Includes.rst.txt |
| 2 | + |
| 3 | +.. _override-templates: |
| 4 | + |
| 5 | +==================== |
| 6 | +Overriding templates |
| 7 | +==================== |
| 8 | + |
| 9 | +By default, the render-guides container uses the Twig templates shipped |
| 10 | +with the official TYPO3 Documentation theme. You can provide your own |
| 11 | +templates to customize or extend the rendering output **without modifying |
| 12 | +the container image**. |
| 13 | + |
| 14 | +.. important:: |
| 15 | + |
| 16 | + Custom templates are only supported when you build the documentation |
| 17 | + **locally** (for example using Docker or DDEV) or within your **own |
| 18 | + CI/CD pipeline**. |
| 19 | + |
| 20 | + When your project documentation is built and deployed automatically via |
| 21 | + the **official TYPO3 documentation workflow** (to |
| 22 | + `https://docs.typo3.org <https://docs.typo3.org>`_), custom templates |
| 23 | + are **not supported**. |
| 24 | + |
| 25 | + The central rendering service uses a fixed, controlled version of the |
| 26 | + official theme to ensure consistency across all published manuals. |
| 27 | + |
| 28 | +.. _template-override-mechanism: |
| 29 | + |
| 30 | +How template overriding works |
| 31 | +============================= |
| 32 | + |
| 33 | +The TYPO3 Documentation theme registers a list of template search paths. |
| 34 | +When rendering, the Twig template engine resolves templates by checking |
| 35 | +these paths **in order** and using the first match. |
| 36 | + |
| 37 | +When custom template directories are present, they are prepended to the |
| 38 | +search path, giving them higher priority than the built-in templates. |
| 39 | + |
| 40 | +The resolution order is: |
| 41 | + |
| 42 | +#. Custom templates mounted via Docker volume at :file:`/templates` |
| 43 | + (highest priority) |
| 44 | +#. Custom templates bundled in the project at |
| 45 | + :file:`resources/custom-templates` (relative to the project root) |
| 46 | +#. TYPO3-specific theme templates |
| 47 | +#. Bootstrap 5 theme templates (fallback) |
| 48 | +#. Base phpDocumentor templates (fallback) |
| 49 | + |
| 50 | +.. _template-docker-volume: |
| 51 | + |
| 52 | +Method 1: mount a Docker volume |
| 53 | +=============================== |
| 54 | + |
| 55 | +Mount a local directory into the container at the path :file:`/templates`. |
| 56 | + |
| 57 | +For example, if your custom templates are stored in a folder named |
| 58 | +:file:`my-custom-templates` in your current working directory: |
| 59 | + |
| 60 | +.. code-block:: shell |
| 61 | +
|
| 62 | + docker run --rm \ |
| 63 | + --pull always \ |
| 64 | + -v "$(pwd):/project" \ |
| 65 | + -v "$(pwd)/my-custom-templates:/templates:ro" \ |
| 66 | + -it ghcr.io/typo3-documentation/render-guides:latest \ |
| 67 | + --progress --config=Documentation |
| 68 | +
|
| 69 | +.. note:: |
| 70 | + |
| 71 | + The :file:`/templates` path is **separate from** the :file:`/project` |
| 72 | + mount point. This avoids volume mount ordering issues that can occur |
| 73 | + when nesting volumes. |
| 74 | + |
| 75 | +.. _template-project-bundled: |
| 76 | + |
| 77 | +Method 2: bundle templates in your project |
| 78 | +========================================== |
| 79 | + |
| 80 | +Place your custom templates in a directory named |
| 81 | +:file:`resources/custom-templates` **at the root of your repository**: |
| 82 | + |
| 83 | +.. code-block:: text |
| 84 | +
|
| 85 | + my-project/ |
| 86 | + |-- Documentation/ |
| 87 | + | |-- Index.rst |
| 88 | + | +-- ... |
| 89 | + |-- resources/ |
| 90 | + | +-- custom-templates/ |
| 91 | + | +-- structure/ |
| 92 | + | +-- layout.html.twig |
| 93 | + +-- ... |
| 94 | +
|
| 95 | +When you mount your project into the container with |
| 96 | +``-v "$(pwd):/project"``, the path |
| 97 | +:file:`/project/resources/custom-templates` is detected automatically. |
| 98 | +No extra volume mount is needed: |
| 99 | + |
| 100 | +.. code-block:: shell |
| 101 | +
|
| 102 | + docker run --rm \ |
| 103 | + --pull always \ |
| 104 | + -v "$(pwd):/project" \ |
| 105 | + -it ghcr.io/typo3-documentation/render-guides:latest \ |
| 106 | + --progress --config=Documentation |
| 107 | +
|
| 108 | +.. _template-directory-structure: |
| 109 | + |
| 110 | +Directory structure for custom templates |
| 111 | +======================================== |
| 112 | + |
| 113 | +Your custom templates must mirror the internal directory structure of the |
| 114 | +built-in templates you want to override. |
| 115 | + |
| 116 | +For example, if the original file is located at: |
| 117 | + |
| 118 | +.. code-block:: text |
| 119 | +
|
| 120 | + typo3-docs-theme/resources/template/structure/layout.html.twig |
| 121 | +
|
| 122 | +then your custom file must be placed at: |
| 123 | + |
| 124 | +.. code-block:: text |
| 125 | +
|
| 126 | + my-custom-templates/structure/layout.html.twig |
| 127 | +
|
| 128 | +When both files exist, your version is used instead of the original. |
| 129 | +Any template you do **not** override continues to use the built-in |
| 130 | +version. |
| 131 | + |
| 132 | +.. _template-finding-originals: |
| 133 | + |
| 134 | +Finding the original templates |
| 135 | +============================== |
| 136 | + |
| 137 | +To create a customized version of a template, first copy the original |
| 138 | +from the container image. |
| 139 | + |
| 140 | +Open a shell inside the container to browse all available templates: |
| 141 | + |
| 142 | +.. code-block:: shell |
| 143 | +
|
| 144 | + docker run --rm -it \ |
| 145 | + --entrypoint=sh \ |
| 146 | + ghcr.io/typo3-documentation/render-guides:latest |
| 147 | +
|
| 148 | +.. note:: |
| 149 | + |
| 150 | + The ``--entrypoint=sh`` flag is required because the container's |
| 151 | + default entrypoint routes all commands to the PHP guides application. |
| 152 | + Without it, shell commands like ``cat`` or ``ls`` would be |
| 153 | + interpreted as guides subcommands. |
| 154 | + |
| 155 | +Once inside, the templates are organized as follows: |
| 156 | + |
| 157 | +.. list-table:: |
| 158 | + :header-rows: 1 |
| 159 | + :widths: 30 70 |
| 160 | + |
| 161 | + * - **Theme / Purpose** |
| 162 | + - **Location in container** |
| 163 | + * - TYPO3-specific templates |
| 164 | + - :file:`/opt/guides/packages/typo3-docs-theme/resources/template/` |
| 165 | + * - Bootstrap 5 theme templates |
| 166 | + - :file:`/opt/guides/vendor/phpdocumentor/guides-theme-bootstrap/resources/template/` |
| 167 | + * - reStructuredText (reST) templates |
| 168 | + - :file:`/opt/guides/vendor/phpdocumentor/guides-restructured-text/resources/template/html/` |
| 169 | + * - Base templates (shared core) |
| 170 | + - :file:`/opt/guides/vendor/phpdocumentor/guides/resources/template/html/` |
| 171 | + |
| 172 | +.. _template-copying: |
| 173 | + |
| 174 | +Copying a template from the container |
| 175 | +------------------------------------- |
| 176 | + |
| 177 | +To copy a specific template to your local machine, use |
| 178 | +``--entrypoint=cat``: |
| 179 | + |
| 180 | +.. code-block:: shell |
| 181 | +
|
| 182 | + docker run --rm \ |
| 183 | + --entrypoint=cat \ |
| 184 | + ghcr.io/typo3-documentation/render-guides:latest \ |
| 185 | + /opt/guides/packages/typo3-docs-theme/resources/template/structure/layout.html.twig \ |
| 186 | + > my-custom-templates/structure/layout.html.twig |
| 187 | +
|
| 188 | +Make sure the target directory exists before running the command: |
| 189 | + |
| 190 | +.. code-block:: shell |
| 191 | +
|
| 192 | + mkdir -p my-custom-templates/structure |
| 193 | +
|
| 194 | +Edit the copied file locally. The next time you run the container with |
| 195 | +your custom templates mounted, your modified version will automatically |
| 196 | +be used. |
| 197 | + |
| 198 | +.. _template-examples: |
| 199 | + |
| 200 | +Examples |
| 201 | +======== |
| 202 | + |
| 203 | +Override the page layout |
| 204 | +------------------------ |
| 205 | + |
| 206 | +.. code-block:: shell |
| 207 | +
|
| 208 | + mkdir -p my-custom-templates/structure |
| 209 | +
|
| 210 | + docker run --rm \ |
| 211 | + --entrypoint=cat \ |
| 212 | + ghcr.io/typo3-documentation/render-guides:latest \ |
| 213 | + /opt/guides/packages/typo3-docs-theme/resources/template/structure/layout.html.twig \ |
| 214 | + > my-custom-templates/structure/layout.html.twig |
| 215 | +
|
| 216 | + # Edit my-custom-templates/structure/layout.html.twig to your liking |
| 217 | +
|
| 218 | + docker run --rm \ |
| 219 | + -v "$(pwd):/project" \ |
| 220 | + -v "$(pwd)/my-custom-templates:/templates:ro" \ |
| 221 | + -it ghcr.io/typo3-documentation/render-guides:latest \ |
| 222 | + --progress --config=Documentation |
| 223 | +
|
| 224 | +Override block quote rendering |
| 225 | +------------------------------ |
| 226 | + |
| 227 | +.. code-block:: shell |
| 228 | +
|
| 229 | + mkdir -p my-custom-templates/body |
| 230 | +
|
| 231 | + docker run --rm \ |
| 232 | + --entrypoint=cat \ |
| 233 | + ghcr.io/typo3-documentation/render-guides:latest \ |
| 234 | + /opt/guides/vendor/phpdocumentor/guides/resources/template/html/body/quote.html.twig \ |
| 235 | + > my-custom-templates/body/quote.html.twig |
| 236 | +
|
| 237 | + # Edit and render as above |
0 commit comments