-
Notifications
You must be signed in to change notification settings - Fork 59
[FEATURE] Show how to override FSC templates #287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3b5846b
[FEATURE] Show how to override FSC templates
linawolf 70a6df5
Apply suggestions from code review
linawolf 6fb201c
[FEATURE] Show how to override FSC templates
linawolf 62af076
Apply suggestions from code review
linawolf 03d5cbb
Update Documentation/ContentElementRendering/Index.rst
linawolf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| .. Generated by https://github.com/TYPO3-Documentation/t3docs-codesnippets | ||
| .. Extracted from EXT:site_package/Resources/Private/ContentElements/Partials/Media/Rendering/Image.html | ||
|
|
||
| .. code-block:: html | ||
| :caption: EXT:site_package/Resources/Private/ContentElements/Partials/Media/Rendering/Image.html | ||
| :linenos: | ||
|
|
||
| <html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true"> | ||
| <f:media class="image-embed-item rounded-circle" file="{file}" width="{dimensions.width}" height="{dimensions.height}" alt="{file.alternative}" title="{file.title}" loading="{settings.media.lazyLoading}" decoding="{settings.media.imageDecoding}" /> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| .. Generated by https://github.com/TYPO3-Documentation/t3docs-codesnippets | ||
| .. Extracted from EXT:site_package/Resources/Private/ContentElements/Templates/MenuSitemap.html | ||
|
|
||
| .. code-block:: html | ||
| :caption: EXT:site_package/Resources/Private/ContentElements/Templates/MenuSitemap.html | ||
| :linenos: | ||
|
|
||
| <html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true"> | ||
| <f:layout name="Default" /> | ||
| <f:section name="Main"> | ||
|
|
||
| <f:render section="Menu" arguments="{menu: menu, level: 1}" /> | ||
|
|
||
| </f:section> | ||
| <f:section name="Menu"> | ||
|
|
||
| <f:if condition="{menu}"> | ||
| <ul class="list-group ps-4 mt-2"> | ||
| <f:for each="{menu}" as="page"> | ||
| <li class="list-group-item"> | ||
| <a href="{page.link}" class="text-decoration-none text-dark {f:if(condition: '{level} < 2', then: 'fw-bold')}"> | ||
| <span>{page.title}</span> | ||
| </a> | ||
| <f:render section="Menu" arguments="{menu: page.children, level: '{level + 1}'}" /> | ||
| </li> | ||
| </f:for> | ||
| </ul> | ||
| </f:if> | ||
|
|
||
| </f:section> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| .. Generated by https://github.com/TYPO3-Documentation/t3docs-codesnippets | ||
| .. Extracted from EXT:site_package/Resources/Private/ContentElements/Templates/MenuSubpages.html | ||
|
|
||
| .. code-block:: html | ||
| :caption: EXT:site_package/Resources/Private/ContentElements/Templates/MenuSubpages.html | ||
| :linenos: | ||
|
|
||
| <html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true"> | ||
| <f:layout name="Default" /> | ||
| <f:section name="Main"> | ||
|
|
||
| <f:if condition="{menu}"> | ||
| <ul class="nav flex-column"> | ||
| <f:for each="{menu}" as="page"> | ||
| <li class="nav-item"> | ||
| <a href="{page.link}" class="nav-link{f:if(condition: 'page.active', then: 'active')}"> | ||
| <span>{page.title}</span> | ||
| </a> | ||
| </li> | ||
| </f:for> | ||
| </ul> | ||
| </f:if> | ||
|
|
||
| </f:section> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| :navigation-title: Content Element rendering | ||
| .. include:: /Includes.rst.txt | ||
|
|
||
| .. _content-element-rendering: | ||
|
|
||
| ==================================================== | ||
| Overriding the default templates of content elements | ||
| ==================================================== | ||
|
|
||
| The content elements that are rendered up to this point are rendered by the | ||
| TYPO3 system extension Fluid Styled Content (:composer:`typo3/cms-fluid-styled-content`). | ||
|
|
||
| This extensions offers default templates to render content elements. Without | ||
| such an extension, no content would be rendered at all. The default | ||
| templates provided by this extension can be overridden with site settings | ||
| provided by Fluid Styled Content. | ||
|
|
||
| .. contents:: | ||
|
|
||
| .. _content-element-rendering-settings: | ||
|
|
||
| Use Settings to override template paths of Fluid Styled Content | ||
| =============================================================== | ||
|
|
||
| Site settings can be saved both in the site configuration and in the site | ||
| package extension. | ||
|
|
||
| We will save the settings to the site package but use the settings editor to | ||
| write the YAML for us. | ||
|
|
||
| Go to module :guilabel:`Site Management > Settings` and edit the settings of | ||
| your site. Override the paths to the templates of Fluid Styled Content like this: | ||
|
|
||
| .. figure:: /Images/SiteSettingsFsc.png | ||
| :alt: Screenshot demonstrating the site settings module | ||
|
|
||
| Override the templates of Fluid Styled Content | ||
|
|
||
| If you would click :guilabel:`Save` now, the settings would be saved to your | ||
| site configuration at :path:`config/sites/my-site/settings.yaml`. We however | ||
| want to save the settings to the site set of our site package extension. | ||
|
|
||
| Click the button :guilabel:`YAML export` to copy the configuration to your | ||
| Clipboard instead, then save it to the following file: | ||
|
|
||
| .. code-block:: yaml | ||
| :caption: packages/site_package/Configuration/Sets/SitePackage/settings.yaml | ||
|
|
||
| styles: | ||
| templates: | ||
| templateRootPath: 'EXT:site_package/Resources/Private/ContentElements/Templates' | ||
| partialRootPath: 'EXT:site_package/Resources/Private/ContentElements/Partials' | ||
| layoutRootPath: 'EXT:site_package/Resources/Private/ContentElements/Layouts' | ||
|
|
||
| Then close the settings editor without saving. You can now start overriding the | ||
| templates: | ||
|
|
||
| .. _content-element-rendering-menu-subpages: | ||
|
|
||
| Override the "Menu of Subpages" template | ||
| ======================================== | ||
|
|
||
| On "Page 1" of the example data a content element of type "Subpages" was added. | ||
| We now have to find out what this type is called in the database. The raw values | ||
| saved to the database are displayed in the TYPO3 backend when the debug mode | ||
| is activated: | ||
|
|
||
| .. figure:: /Images/MenuContentElement.png | ||
| :alt: Screenshot demonstrating the backend debug mode for Content element "Subpages" on "Page 1" | ||
|
|
||
| You can now see that the Type (saved in field `CType`) is stored as `menu_subpages` | ||
|
|
||
| Now we must find and copy the original template from Fluid Styled Content. TYPO3 | ||
| extensions are saved by their composer key, here :composer:`typo3/cms-fluid-styled-content`, | ||
| into the folder :path:`vendor` during installation via Composer. You can find | ||
| the files belonging to Fluid Styled Content in folder | ||
| :path:`vendor/typo3/cms-fluid-styled-content` therefore. This folder is | ||
| structured similarly to your site package extension and you can find the original | ||
| templates in folder :path:`Resources/Private/Templates` here. | ||
|
|
||
| By convention the templates of Fluid Styled Content have the name of the `CType` in CamelCase. Copy file | ||
| :path:`vendor/typo3/cms-fluid-styled-content/Resources/Private/Templates/MenuSubpages.html` | ||
| into folder :path:`packages/my_site_package/Resources/Private/ContentElements/Templates/MenuSubpages.html` | ||
|
|
||
| Edit the file to add some classes as used in menus in Bootstrap, for example | ||
| like this: | ||
|
|
||
| .. include:: /CodeSnippets/Fluid/MenuSubpages.rst.txt | ||
|
|
||
| In most parts the changes we made are pretty straight forward. In line 9 | ||
| we use the `Fluid inline notation <https://docs.typo3.org/permalink/t3coreapi:fluid-inline-notation>`_ | ||
| of the :ref:`If ViewHelper <f:if> <t3viewhelper:typo3fluid-fluid-if>` to only | ||
| output class `active` if the page in the menu is in the root line. | ||
|
|
||
| .. _content-element-rendering-sitemap: | ||
|
|
||
| Override the sitemap template | ||
| ============================= | ||
|
|
||
| In a similar fashion we now copy and adjust the template for the sitemap from | ||
| :path:`vendor/typo3/cms-fluid-styled-content/Resources/Private/Templates/MenuSitemap.html` | ||
| into folder :path:`packages/site_package/Resources/Private/ContentElements/Templates/MenuSitemap.html` | ||
| and then adjust it: | ||
|
|
||
| .. include:: /CodeSnippets/Fluid/MenuSitemap.rst.txt | ||
|
|
||
| We want to adjust the HTML output of the sitemap for different levels. The | ||
| original template however gives us no means to output the level. | ||
|
|
||
| Line 5 uses the ViewHelper :ref:`Render ViewHelper <f:render> <t3viewhelper:typo3-fluid-render>` | ||
| to render everything in the section defined in lines 8-23. | ||
|
|
||
| In the original template the argument `menu` was already passed on as variable to | ||
| the section. We now enhance this line to also pass on variable `level` set to 1. | ||
|
|
||
| In line 17 the section `Menu` recursively includes itself to display further | ||
| levels of the sitemap. We now add 1 to the level so that within the recursive | ||
| call we are in level 2. | ||
|
|
||
| In line 14 we use that level to determine which class to use for the page link, | ||
| using once more the `Fluid inline notation <https://docs.typo3.org/permalink/t3coreapi:fluid-inline-notation>`_ | ||
| of the :ref:`If ViewHelper <f:if> <t3viewhelper:typo3fluid-fluid-if>`. | ||
|
|
||
| .. _content-element-rendering-image: | ||
|
|
||
| Override the partial template for image rendering | ||
| ================================================= | ||
|
|
||
| The templates of some content elements use the | ||
| :ref:`Render ViewHelper <f:render> <t3viewhelper:typo3-fluid-render>` to include | ||
| a partial template. This is true wherever images are displayed for example. | ||
|
|
||
| Partials in turn can include different partials. | ||
|
|
||
| The templates for "Image" and "Textpic" both contain the following line: | ||
|
|
||
| .. code-block:: html | ||
| :caption: vendor/typo3/cms-fluid-styled-content/Resources/Private/Templates/Image.html (Excerpt) | ||
|
|
||
| <f:render partial="Media/Gallery" arguments="{_all}" /> | ||
|
|
||
| If you open that partial, it includes yet another partial: | ||
|
|
||
| .. code-block:: html | ||
| :caption: vendor/typo3/cms-fluid-styled-content/Resources/Private/Partials/Media/Gallery.html (Excerpt) | ||
|
|
||
| <f:render partial="Media/Type" arguments="{file: column.media, dimensions: column.dimensions, data: data, settings: settings}" /> | ||
|
|
||
| Which contains another until we finally arrive at | ||
| :path:`vendor/typo3/cms-fluid-styled-content/Resources/Private/Partials/Media/Rendering/Image.html` | ||
| which does contain the actual :ref:`Media ViewHelper <f:media> <t3viewhelper:typo3-fluid-media>`. | ||
|
|
||
| By overriding this one partial we can add a class to all images that are | ||
| displayed with the "Image" or "Text with Media" content elements. For example | ||
| we could display all images as circles by adding the class `rounded-circle`: | ||
|
|
||
| .. include:: /CodeSnippets/Fluid/Image.rst.txt |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.