A site package is a custom TYPO3 extension
that contains files regarding the theme and functionality of a site.
This tutorial describes step by step how to come from your first TYPO3
installation to the first basic site.
You can use the Site Package Builder to
create a customized site package. If you want to follow this tutorial, choose
"Site Package Tutorial" as base package.
Note
The example site package is structured for educational purposes and is
not intended for use in production environments.
We introduce the templating engine Fluid, that is used to render the
html pieces in a logically manner. Then we describe the directory
structure that is needed in a site package extension. We also
explain the first steps to include the previously static files and
html pieces using Fluid.
Here we explain the purpose of backend layouts. Additionally we
introduce the DatabaseQueryProcessor which is used to render content
from a special "colPos" previously defined in the backend layout.
We use Fluid to output content from a specific colPos. By this we
get to know the cObject ViewHelper.
We introduce the main menu, explain how we build up a menu
processor with TypoScript and how we can output the menu with Fluid.
We introduce the so called "Debug ViewHelper".
In this section we configure the site package using the new
concept of site sets. The settings are now stored in a yaml file
called settings.definitions.yaml.
If you used the Site Package Builder, file packages/my_site_package/README.md
contains instructions on how to install your site package.
Move / unzip your extension folder my_site_package/ into the packages/
folder. Then require the extension via Composer using the
package name defined in the site package extension's composer.json now located
at packages/my_site_package/
name:my-vendor/my-site-packagelabel:'My Site Package'dependencies:-typo3/fluid-styled-content-typo3/fluid-styled-content-css
Copied!
You will learn more about site sets in chapter
The site set.
You can find the complete reference in TYPO3 explained:
Site sets.
During installation of your site package a page tree with example content was
created, and should already have a site configuration in folder
config/sites/main.
When you look at the site configuration in module Site Management > Sites
it should already contain the set "My Site package". Other sets, for example
if you want to use
typo3/cms-form
can be added here.
Use module Site Management > Sites to add the "Example: My Site package"
If you made no changes, the site configuration should look like this:
config/sites/main/config.yaml
base:'/'dependencies:-my-vendor/my-site-packagelanguages:-title:Englishenabled:truelanguageId:0base:/locale:en_US.UTF-8navigationTitle:Englishflag:usrootPageId:1websiteTitle:'My Site Package'
TYPO3 uses TypoScript as configuration language. The TypoScript is used to
configure the templates, which are created with the templating language Fluid.
A file called packages/my_site_package/Configuration/Sets/SitePackage/setup.typoscript
provides the TypoScript to your site. This file contains imports of files from
folder packages/my_site_package/Configuration/Sets/SitePackage/TypoScript
which contain the actual configuration.
File packages/my_site_package/Configuration/Sets/SitePackage/TypoScript/page.typoscript
Defines how the output of all pages of the site is rendered with Fluid templates:
page = PAGEpage {10 = PAGEVIEW10 { paths { 0 = EXT:my_site_package/Resources/Private/PageView/10 = {$MySitePackage.template_path} } dataProcessing {# makes content elements available as {content} in Fluid template10 = page-content } } shortcutIcon = {$MySitePackage.favicon}}
Copied!
Line 6 defines from what directory the Fluid Templates are loaded. Line 7 allows
to override this part via settings.
Learn more about using Fluid Templates in chapter Fluid Templates.
Preview page
Whenever we have made changes to the Fluid templates or TypoScript files, it is
necessary to Flush frontend caches in the menu in the
top bar before you can preview the page properly:
Flush the frontend cache after changing template files
You can then preview your page by clicking on the button View webpage
in the page module.
At the top of the composer.json file we see the Composer package name
my-vendor/my-site-package (with a dash) and at the bottom we see the TYPO3
extension key in the extra section - my_site_package (with an underscore).
The Composer "name" consists of a vendor name followed by a forward slash and the
lowercase extension name with dashes.
When you reference files in your extension, the extension key is used, for
example when setting your favicon in TypoScript:
To follow this tutorial you need to have a few pages in your page tree and some
content elements on those pages. You also need a basic site configuration.
The site package you build in chapter
Generate a site package
creates a folder called Initialisation. This folder contains an example
page tree with some dummy content in file
packages/my_site_package/Initialisation/data.xml,
and an example site configuration in file
packages/my_site_package/Initialisation/Site/main/config.yaml. Folder
packages/my_site_package/Initialisation/data.xml.files contains
some example images to demonstrate using certain content elements.
Loading the data might take a few seconds. If you do not see the new pages try
reloading the backend.
The page tree in the module Web > Page now contains a few example pages.
Note
This only works for site packages of type "Site Package Tutorial". The ones
based on the Bootstrap Package or Fluid Styled Content do not contain example
data.
Assets usually include CSS files, JavaScript and images / icons used for design
purposes.
Within an extension, including a site package, assets can only be placed in folder
Resources/Public and subfolders of this folder. This folder will be
symlinked into public/_assets/<some hash>.
Note
You must never reference any file in public/_assets directly by
using the hash in an absolute or relative URL. The hashes can change at any
time. Only use TYPO3 library methods to reference the assets.
Repairing the symlinks from packages/my_site_package/Resources/Public into public/_assets
In case you installed a site package before it had a folder called
Resources/Public the symlinks did not get automatically created
during Composer installation.
In that case you can tell Composer to
re-perform this initialization-process, which is done in the "dump-autoload" step.
During that process the symlinks will also be created by Composer.
ddev composer dump-autoload
Copied!
Managing asset dependencies in real life projects
It is technically possible to use a CDN (Content Delivery Network) to include
libraries in TYPO3. However there are privacy and security risks attached to
this and it might be a GDPR Violation. Therefore we recommend to host all files
yourself by placing them in the Resources/Public folder.
In a later step, you can use npm (Node Package
Manager) to manage your JavaScript and CSS dependencies locally. We also
recommend using a JavaScript bundler like Vite.
If you decide to use a frontend bundler, make sure that the resulting asset
files are placed in a publicly available folder, like Resources/Public
in your site package.
You have familiarized yourself with Asset handling in TYPO3
(CSS, JavaScript, design related images, ...)
After this tutorial you have a better understanding of the example templates and
how to adjust them to your needs. You should also be able to create some
templates yourself.
If you prefer to start with a pure HTML template and build all templates
step by step, you can alternatively have a look a Fluid Templates from the Scratch.
The Fluid templates for the whole page have to be configured via TypoScript.
In the example site package that was Generated for you
the according TypoScript can be found in file
packages/my_site_package/Configuration/Sets/SitePackage/TypoScript/page.typoscript:
page = PAGEpage {10 = PAGEVIEW10 { paths { 0 = EXT:my_site_package/Resources/Private/PageView/10 = {$MySitePackage.template_path} } dataProcessing {# makes content elements available as {content} in Fluid template10 = page-content } } shortcutIcon = {$MySitePackage.favicon}}
Copied!
Line 3 defines that Fluid templates should be used for the page by using the
TypoScript object PAGEVIEW.
In line 6 the default path to the page view templates is defined. The definition
could be extended in line 7 by a setting later own. For now assume all Fluid
templates for the page can be found in folder
packages/my_site_package/Resources/Private/PageView.
The default page template
Unless a different page layout is chosen, PAGEVIEW
expects the main template of the page in file PageView/Pages/Default.html within
the defined folder (packages/my_site_package/Resources/Private/PageView).
In line 1 the Layout ViewHelper <f:layout>
is defined to load a layout template from folder PageView/Layouts. The file
must have the same name of the templated, followed by .html, therefore
file packages/my_site_package/Resources/Private/PageView/Layouts/PageLayout.html
is loaded as layout.
In Line 4 and 7 partial templates are loaded from Partials. They follow
the same naming scheme like the Layout and are therefore located in
files Documentation/CodeSnippets/my_site_package/Resources/Private/PageView/Partials/Content.html
and Documentation/CodeSnippets/my_site_package/Resources/Private/PageView/Partials/Stage.html.
To do this they use the Render ViewHelper <f:render>.
The Fluid layout template
The outer most HTML that is needed for all different page layouts is usually
defined in a layout template:
The layout also renders sections that need to be defined with the
Section ViewHelper <f:section>
in the page template. In line 5 the section is rendered, which is defined in line
2-10 of the "Default" page template. It is possible to define several sections
and to define optional sections. We do not demonstrate that here.
The layout template also loads some more partials, for example to display
menu and the footer.
Outer most HTML structure (body, head)
The outer most HTML structure is usually not handled by your custom templates. It
can be configured via the TypoScript configuration of the
PAGE object.
For example you can use option shortcutIcon
to load a favicon, meta to define meta tags,
or add tags to the body tag using bodyTagAdd.
The page object, including examples is described in detail in the TypoScript
reference, chapter Configure the PAGE in TypoScript.
Line 5 uses the Link.page ViewHelper <f:link.page>
to link to the start page, which is the same like the root page and found in the
variable {site.rootPageId}.
Line 6 uses the Image ViewHelper <f:image>
to display a logo in the footer. The path to the logo and its alt tag are
defined in the settings definition. More about this in chapter
Setting definition.
In line 11 yet another partial is included. This partial displays a menu in the
footer. More about this topic in chapter Configure the menus.
Next steps: Fetch the content and configure the menus
Copy the main static HTML file from
Resources/Public/StaticTemplate/default.html
to Resources/Private/PageView/Pages/Default.html. You can override
the file created in step Minimal site package - The TYPO3 Fluid
version. The file name must begin
with a capital letter
The template name Default.html is used as a fall back if no other template
names are defined. Do not change it for now.
Even though this file ends on .html it will be interpreted by the templating
engine Fluid.
TYPO3 takes care of creating the outermost HTML structure of the site, including
the <html> and <head> tags therefore they need to be removed from the
template:
Each time you change a Fluid template you must flush the caches. Fluid
templates preprocessed into PHP files and stored in the folder
var/cache/code/fluid_template.
Flush all caches and preview the page.
.. todo: Link to cache and preview pages in getting started once they exist
When you load your page and inspect it with the developer tools of your browser
you will notice that the assets are loaded from paths like
/_assets/99a57ea771f379715c522bf185e9a315/Css/main.css?1728057333. You must
never try to use these path directly, for example as absolute paths. They can
change at any time. Only use the EXT: syntax.
When you now preview the page you will notice that the your page is loaded
with the dummy content from the template and functioning CSS and JavaScript.
The logo however is not found.
Just like happened with the CSS paths in step Load assets (CSS, JavaScript) the path to the
image is now replaced in the output by a path like
/_assets/99a57ea771f379715c522bf185e9a315/Images/logo.svg?1728057333.
Split up the template into partials
If you compare the two static templates
Resources/Public/StaticTemplate/default.html
and Resources/Public/StaticTemplate/subpagepage.html they share many
parts like the footer or the header with the menu. In order to reuse those parts
we extract them to their own Fluid files. These are called partials and stored
in path Resources/Private/PageView/Partials.
The Fluid template Resources/Private/PageView/Pages/Default.html
should now look like this:
Resources/Private/PageView/Pages/Default.html
<f:asset.cssidentifier="bootstrap"href="EXT:site_package/Resources/Public/Libaries/bootstrap-5.3.3-dist/css/bootstrap.min.css" /><f:asset.cssidentifier="main"href="EXT:site_package/Resources/Public/Css/main.css" /><main><f:renderpartial="Header"arguments="{_all}"/><f:renderpartial="Stage"arguments="{records: content.stage.records}"/><divclass="container"><h2>Start page content</h2><p>The content of the start page is displayed here. This content should be generated from the content element of the startpage </p></div><f:renderpartial="Footer"arguments="{_all}"/></main><f:asset.scriptidentifier="bootstrap"src="EXT:site_package/Resources/Public/Libaries/bootstrap-5.3.3-dist/js/bootstrap.bundle.min.js" /><f:asset.scriptidentifier="main"src="EXT:site_package/Resources/Public/JavaScript/main.js" />
Partials can also be rendered from within another partial. We move the menu in
the partial Resources/Private/PageView/Partials/Header.html to its
own partial, Resources/Private/PageView/Partials/Navigation/Menu.html:
Chapter Main menu will teach you how
to make the menu work.
Extract the footer menu into a partial
We can also move the footer menu from
the partial Resources/Private/PageView/Partials/Footer.html to its
own partial, Resources/Private/PageView/Partials/Navigation/FooterMenu.html:
<f:asset.css identifier="bootstrap" href="EXT:site_package/Resources/Public/Libaries/bootstrap-5.3.3-dist/css/bootstrap.min.css" />
<f:asset.css identifier="main" href="EXT:site_package/Resources/Public/Css/main.css" />
<main>
<f:render partial="Header" arguments="{_all}"/>
- <f:render partial="Stage" arguments="{records: content.stage.records}"/>- <div class="container">- <h2>Start page content</h2>- <p>The content of the start page is displayed here. This content should be generated from the content element of the startpage </p>- </div>+ <f:render section="Main"/>
<f:render partial="Footer" arguments="{_all}"/>
</main>
<f:asset.script identifier="bootstrap" src="EXT:site_package/Resources/Public/Libaries/bootstrap-5.3.3-dist/js/bootstrap.bundle.min.js" />
<f:asset.script identifier="main" src="EXT:site_package/Resources/Public/JavaScript/main.js" />
+<f:section name="Main">+ <f:render partial="Stage" arguments="{_all}"/>+ <div class="container">+ <h2>Start page content</h2>+ <p>The content of the start page is displayed here. This content should be generated from the content element of the startpage </p>+ </div>+</f:section>
Copied!
The result looks like this:
Resources/Private/PageView/Pages/Default.html
<f:asset.cssidentifier="bootstrap"href="EXT:site_package/Resources/Public/Libaries/bootstrap-5.3.3-dist/css/bootstrap.min.css" /><f:asset.cssidentifier="main"href="EXT:site_package/Resources/Public/Css/main.css" /><main><f:renderpartial="Header"arguments="{_all}"/><f:rendersection="Main"/><f:renderpartial="Footer"arguments="{_all}"/></main><f:asset.scriptidentifier="bootstrap"src="EXT:site_package/Resources/Public/Libaries/bootstrap-5.3.3-dist/js/bootstrap.bundle.min.js" /><f:asset.scriptidentifier="main"src="EXT:site_package/Resources/Public/JavaScript/main.js" /><f:sectionname="Main"><f:renderpartial="Stage"arguments="{records: content.stage.records}"/><divclass="container"><h2>Start page content</h2><p>The content of the start page is displayed here. This content should be generated from the content element of the startpage </p></div></f:section>
We can repeat the above steps for the subpage and write such a template:
Resources/Private/PageView/Pages/Subpage.html
<f:asset.cssidentifier="bootstrap"href="EXT:site_package/Resources/Public/Libaries/bootstrap-5.3.3-dist/css/bootstrap.min.css" /><f:asset.cssidentifier="main"href="EXT:site_package/Resources/Public/Css/main.css" /><main><f:renderpartial="Header"arguments="{_all}"/><f:rendersection="Main"/><f:renderpartial="Footer"arguments="{_all}"/></main><f:asset.scriptidentifier="bootstrap"src="EXT:site_package/Resources/Public/Libaries/bootstrap-5.3.3-dist/js/bootstrap.bundle.min.js" /><f:asset.scriptidentifier="main"src="EXT:site_package/Resources/Public/JavaScript/main.js" /><f:sectionname="Main"><f:renderpartial="Stage"arguments="{_all}"/><f:renderpartial="Navigation/Breadcrumb"arguments="{_all}"/><divclass="container"><divclass="row"><divclass="col-md-8"><divclass="h-100 p-5 text-bg-white"><h2>Page content</h2><p>The content of each page can be displayed here. </p></div></div><divclass="col-md-4"><divclass="h-100 p-5 bg-body-tertiary"><h2>Sidebar </h2><p>Place for some shared content</p></div></div></div></div></f:section>
Copied!
Extract the breadcrumb into a partial
The subpage template contain a breadcrumb, between stage and content, that
you can also move to a partial.
Lines 1-9 of file Subpage.html in step The Fluid template for the subpage step are exactly the
same like in file Resources/Private/PageView/Pages/Default.html.
You can use the Site Package Builder to
create a customized site package. If you want to follow this tutorial, choose
"Site Package Tutorial" as base package.
Display the content elements on your page
In step Move the content into a section we moved the part of our template, that will
contain the content, into its own section. This section is however still filled
with dummy content:
Resources/Private/PageView/Pages/Default.html
<f:layoutname="Layout"/><f:sectionname="Main"><f:renderpartial="Stage"arguments="{_all}"/><divclass="container"><h2>Start page content</h2><p>The content of the start page is displayed here. [...] </p></div></f:section>
Add a dependency to the sets provided by the system extension
typo3/cms-fluid-styled-content
. This step is a prerequisite to
display the content in the next steps.
Your site set configuration should now look like this:
name:my-vendor/my-site-packagelabel:'My Site Package'dependencies:-typo3/fluid-styled-content-typo3/fluid-styled-content-css
Copied!
Create a default page layout with page TSconfig
In order to map the content from the backend to the frontend we create a
new file Configuration/Sets/SitePackage/page.tsconfig containing page TSconfig.
By placing the file within the site set, you created in step
Create a basic site set, the
newly created file is loaded within the page tree of your site automatically:
Each area in the page layout becomes an identifier that can be used during
content mapping. If no content element is added in the backend of that page and
the slide mode is activated, content from the parent page is displayed. This is
useful for design elements like side bars, jumbotrons or banners that should be
the same for a page and its subpage. You can find all details of the
Page / backend layouts in the TSconfig reference.
When you make changes to the files of an extension it is usually necessary
to flush all caches by hitting the button.
Flush all caches
After flushing the all caches the new backend layout is available in the page
properties at Appearance > Page Layout > Backend Layout.
Choose the backend layout
Choose the page layout in the page properties
Switch to the new backend layout and save the page properties. In the
Page module you will see two areas called "Stage" and
"Main Content" now.
In the database each content element record is stored in the table
tt_content. This table has a column called colPos. If the value stored
in column colPos is the same as defined in the page layout in page TSconfig
the content element is displayed in the according area of the page layout.
It is considered best practice to store the main content in an area with
colPos=0. This makes switching between different layouts easier.
Content rendering via page-content data processor
New in version TYPO3 13
The TypoScript object PAGEVIEW and the data processor page-content
have been added.
Did you define the correct data processor page-content in TypoScript?
Did you override the default variable name using
as in the data processor?
TypoScript mapping in Fluid template
Open the file Resources/Private/PageView/Page/Default.html and locate the
main content area. It contains a headline (look for the <h2>-tags) and
some dummy content (look for the <p>-tags).
fluid-styled-content internally uses
Fluid templates and TypoScript with data processors just like the ones we were
defining above. If you desire to change the output of these content elements
you could override the Fluid templates of the extension
typo3/cms-fluid-styled-content
.
Extract the content element rendering to a partial
As we want to reuse the Fluid part about rendering content elements in the
next steps, we extract it into a partial, like we did with the menu in
step Extract the menu into a partial.
We want to be able to render content elements of any content area. Therefore pass
the records of the page layout area to be rendered as variable records to
the partial:
At this point the file packages/my_site_package/Configuration/Sets/SitePackage/setup.typoscript
has started to have several lines. When we start rendering the
Menues,
make more sophisticated
Settings
etc the TypoScript configuration file is going to grow more.
We therefore suggest, to use TypoScript imports
and structure your TypoScript in different files that are then combined at this point.
The rest of the Tutorial will assume that your files are in the directory
packages/my_site_package/Configuration/Sets/SitePackage/TypoScript/ and imported
as described in TypoScript imports.
In the following chapters we will need additional TypoScript setup
configurations.
Theoretically you could put all TypoScript into one big file and it would work
fine. But you have better overview if you split it up in multiple files ordered
by purpose.
Create a new folder called Configuration/Sets/SitePackage/TypoScript. In this
create a file called page.typoscript and copy the content from
file Configuration/Sets/SitePackage/setup.typoscript
into it.
Then change the latter file to contain the following:
Configuration/Sets/SitePackage/setup.typoscript
@import './TypoScript/page.typoscript'
Copied!
Flush the caches and preview the page. The output should be unchanged.
Import all TypoScript files from a folder using a wildcard
We will create more TypoScript files in the next steps. We could import them
file by file. But as the order will not matter we can import all of them via
wildcard:
The stage has the
colPos1, therefore all content elements in the stage area will automatically have
a 1 instead of a 0 in field "Column" / database column colPos.
The identifier
is stage therefore the content of the content area is available as
variable {content.stage.records} in the partial template.
The slideMode
is set to slide therefore if no content is found in the content area on
the current page, TYPO3 will look one page up etc until content is found
or the page root is reached.
Using a content area with slide mode
The content elements will be automatically found and provided to your template.
Therefore the template for the area "Stage" looks no different from the one
for the main area except that is uses the corresponding variable of course:
Edit the file
packages/my-site-package/Resources/Private/PageView/Pages/Subpage.html.
Exchange the main content area just as we have done before with the default
template. Now
replace the content area of the sidebar with the content elements in the Fluid
variable
{sidebarContent}.
We now create a subpage layout with two columns and a row for the stage in a
new file packages/my-site-package/Configuration/TsConfig/Page/PageLayout/Subpage.tsconfig
containing page TSconfig. :
Switch to the two column layout with a sidebar for subpages
You can now use the Two Column backend layout for the Start page subpages
at Appearance > Page Layout > Backend Layout.
Edit the page properties of Start page to use the backend layout
"Two Columns" for subpages.
Switch to the Backend Layout "Two Columns" for subpages
After saving you will be able to see on "Page 1" that the content of the columns "main" and
"stage" remains unchanged while there is a third column "sidebar".
This is due to the fact that the backend layout "Default" and "TwoColumns"
use the same colPos number for these columns.
The pages generated in step Create initial pages already contain
"Menu of subpages" an example content in "sidebar" column.
A new column "Sidebar" appears
Preview the page once more. A sidebar will appear in the frontend:
The sidebar appears in the frontend
Add content in the TYPO3 backend
The pages generated in step
Create initial pages
already contain some example content.
You can add additonal content in the backend. Go to
Web > Page and select any of the pages you created before,
(for example "Page 2"). Click the + Create new content button
in the column labelled "Main" and choose the "Regular Text
Element" content element.
Create new content element
Choose "Regular Text Element"
Enter a headline and some arbitrary text in the Rich Text Editor (RTE).
Enter a headline
Enter some arbitrary text in the Rich Text Editor (RTE)
Save your changes by clicking button Save at the top.
You can return to the previous view by clicking Close.
Verify if your new content is displayed on the page
Whenever you edit the content elements on
a page the cache of the current page is automatically deleted. If the content
fails to update you should still delete the TYPO3 caches and force your
browser to reload.
You can use a content element to display a menu. In the example data "Page 1"
contains a menu of subpages and page "Sitemap" a sitemap content element.
The debug output on your page should now look like this:
array(8 items)
data => array(78 items)
title => 'My page' (22 chars)
link => '/my-page' (26 chars)
target => '' (0 chars)
active => 0 (integer)
current => 0 (integer)
spacer => 0 (integer)
hasSubpages => 1 (integer)
Copied!
The following data is of interest:
{menuItem.data}:
Contains the raw data of the database record
of the page for the menu item.
{menuItem.link}:
The actual link to the page. For external links it contains the URL.
{menuItem.target}:
This might contain "_blank" if the menu item represents an external link.
{menuItem.title}:
The title to be displayed in the menu. By default the navigation title if set,
the title otherwise.
{menuItem.active}
Contains 1 if the page of the current menu item is in the rootline of the
current page.
The construct {f:if(condition: menuItem.active, then: 'active')}
output the string "active" if {menuItem.active} is set. The syntax might look
confusing at first. It is an If ViewHelper <f:if>
displayed in the Fluid inline notation.
Preview the page and use the menu
Whenever you change TypoScript files or Fluid templates, flush all caches:
ddev typo3 cache:flush
Copied!
Checking from the backend if the menu is generated as expected.
A breadcrumb configured in
packages/my_site_package/Configuration/Sets/SitePackage/TypoScript/Navigation/breadcrumb.typoscript
and rendered in packages/my_site_package/Resources/Private/PageView/Partials/Navigation/Breadcrumb.html.
A footer menu consisting of pages within a selected folder configured in
packages/my_site_package/Configuration/Sets/SitePackage/TypoScript/Navigation/footerMenu.typoscript
and rendered in packages/my_site_package/Resources/Private/PageView/Partials/Navigation/FooterMenu.html.
Breadcrumb / rootline navigation in TYPO3
If you use a Generated site package
it already contains a breadcrumb navigation on the subpages.
page {10 { dataProcessing {30 = menu30 { special = rootline special.range = 0|-1 as = breadcrumb } } }}
Copied!
Line 4: Each data processor must have a unique id. We used 10 for the
page-content data processor
and 20 for the Main menu therefore we now use 30.
Line 6: We configure the menu to use the special type
Rootline.
Line 7: We use the property special.range
to define that the breadcrumb should start at the root level (0) of the site and
include the level of the current page (-1).
Line 8: As the default variable of the menu data processor menu is already in
use for the main menu, we rename the variable to be used for the breadcrumb to
breadcrumb.
Breadcrumb navigation Fluid template
The special type breadcrumb delivers the items of the rootline as an array.
Therefore we can use the For ViewHelper <f:for>
to loop through these elements:
Line 1, 5: The data of the breadcrumb navigation can be found in variable
{breadcrumb}. We defined this in line 8 of the TypoScript.
Line 6: As all items in the breadcrumb navigation are in the rootline of the
current page all are marked as active. We therefore check if the page of the
entry to be displayed is the current page.
Meta menu / Footer menu in TYPO3
A meta menu - often but not always displayed in the footer of a website -
displays only selected pages like "Imprint", "Contact", "Data Privacy", ...
If you use a Generated site package
it already contains a meta menu in the footer of the page.
The special menu type "List" allows you to specify a list of UIDs of pages that
should be displayed in the meta menu. The special menu type "Directory" allows
you to specify a folder or page of which all subpages should be displayed in
the menu. We take the second approach here.
Line 6: The values processed by the data processor should be stored in variable
footerMenu.
Line 7: We configure the menu to use the special type
Directory.
Line 8: The folder which contains the pages to be displayed in the footer menu
can be configured via site settings. You can find the definition of this setting
in file packages/my_site_package/Configuration/Sets/SitePackage/settings.definitions.yaml.
Menu of subpages - Fluid template
The special type directory delivers the items of the meta menu as an array.
Therefore we can use the For ViewHelper <f:for>
to loop through these elements:
As we do not need to highlight active pages in the footer menu we omit those
conditions.
Switching to the menu type list
If it is more feasible for your project to list all pages that should be listed
in the meta menu, you can switch to using the special menu type "List" by
changing the TypoScript:
40 = menu
40 {
as = footerMenu
- special = directory+ special = list
special.value = {$MySitePackage.footerMenuRoot}
}
Copied!
You can now change the setting to accept a comma separated list of integers
and then list all pages that should be displayed in the meta menu. For example:
MySitePackage.footerMenuRoot:
label: 'Footer menu root uid'
- description: 'The subpages of this page are displayed in the footer'+ description: 'These pages are displayed in the footer'
category: MySitePackage.menus
- type: int+ type: stringlist- default: 2+ default:+ - 5+ - 4+ - 3
Copied!
We are using the type stringlist
- as of writing these lines - there is no integer list type in the settings yet.
Site settings: Further configuration options
New in version 13.1
Site sets and settings therein have been introduced with TYPO3 13.1.
In TYPO3 v13.1 and above the TypoScript files are made available as
sets and included in the site. For TYPO3 v12 read the section in
the tutorial for TYPO3 v12.4:
Make TypoScript available (TYPO3 v12.4).
name:my-vendor/my-site-packagelabel:'My Site Package'dependencies:-typo3/fluid-styled-content-typo3/fluid-styled-content-css
Copied!
Line 1 defines the name of the set. As the example site-package extension only
provides one set, the name of the set should be the same as the
composer name.
In line 4 and 5 dependencies are defined. In this example the site package
depends on
typo3/cms-fluid-styled-content
, therefore the sets
provided by this system extension are included as dependency. By doing so all
settings and TypoScript definitions provided by the extension are automatically
included.
Your site set folder now contains the following files:
my_site_package/Configuration/Sets/SitePackage
config.yaml
page.tsconfig
setup.typoscript
Introduce site settings to configure fluid-styled-content
Place a file called settings.yaml in the folder
Configuration/Sets/SitePackage.
Here we override some values for maximal image width in text-media content
elements, we enable a lightbox for images and set paths for overriding the
templates of that extension.
Certain information is used in different parts of the templates over and over
again like the uid of the data privacy page or the contact e-mail address.
You can keep central information in settings. They can then be adjusted as
needed in the Site Management > Settings module in the backend
by administrators.
Setting definition
Settings definitions are used to set values that can be used in the TypoScript
setup throughout the project.
They are stored in the file settings.definitions.yaml in your site set.
The settings can be displayed and adjusted in module
Site Management > Settings:
Administrators can view and adjust settings and save them here.
If administrators change settings here, they get saved to
config/sites/my-site/settings.yaml so this path and file have to be
writable for TYPO3. If the file is not writable for example when you have it
under version control, administrators can als export the settings and download
them.
categories:MySitePackage:label:'My Site Package'MySitePackage.templates:label:'Templates'parent:MySitePackageMySitePackage.layout:label:'Layout'parent:MySitePackagesettings:MySitePackage.template_path:label:'Page template path'category:MySitePackage.templatesdescription:'Path to the templates of the My Site Package.'type:stringdefault:'EXT:my_site_package/Resources/Private/Templates/'MySitePackage.logo:label:'Logo'category:MySitePackage.layoutdescription:'Path to the logo of My Site Package.'type:stringdefault:'EXT:my_site_package/Resources/Public/Images/logo.svg'MySitePackage.logo-alt:label:'Logo Alt text'category:MySitePackage.layoutdescription:'Alternative text of the logo for the visually impaired'type:stringdefault:'Logo'MySitePackage.favicon:label:'Favicon'description:'This icon is displayed in search engine results and in the browser tab'category:MySitePackage.layouttype:stringdefault:'EXT:my_site_package/Resources/Public/Icons/favicon.ico'
Copied!
Settings can be assigned to categories so that they are easier to find for
administrators. These categories are defined in lines 1-12.
Let us now have a look at the definition of a setting entry in detail:
MySitePackage.footerMenuRoot:label:'Footer menu root uid'description:'The subpages of this page are displayed in the footer'category:MySitePackage.menustype:intdefault:2
Copied!
Line 1 defines the identifier of the settings. Identifiers are available
globally within the complete project and installed extensions might define some.
Use a unique prefix therefore. Here we use MySitePackage.. We used the same
prefix for the categories. This is suggested but not mandatory in a site package.
Line 2-3 define labels to be displayed in the backend module.
The site settings are available as variable {settings}
(see settings) within the templates
of the page as we are using the PAGEVIEW
TypoScript object.
In the site package example we display the logo once in the header in large and
once in the footer in smaller and use the settings to determine the path and alt
text in both cases:
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 (
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.
Your site package, if generated by the Site Package Builder already overrides
two templates from Fluid Styled Content and you are free to override additional
ones.
Use Settings to override template paths of Fluid Styled Content
Your site package already configures the paths to override the templates of
Fluid Styled Content content elements in file
packages/site_package/Configuration/Sets/SitePackage/settings.yaml:
If you wanted to create this file yourself you could do it as follows:
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 Site Management > Settings and edit the settings of
your site. Override the paths to the templates of Fluid Styled Content like this:
Override the templates of Fluid Styled Content
If you would click Save now, the settings would be saved to your
site configuration at 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 YAML export to copy the configuration to your
Clipboard instead, then save it to the following file:
Your site package already overrides the template MenuSubpages of
Fluid Styled Content in file
packages/my_site_package/Resources/Private/ContentElements/Templates/MenuSubpages.html.
If you wanted to create this Template manually you could do it like this:
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:
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
typo3/cms-fluid-styled-content
,
into the folder vendor during installation via Composer. You can find
the files belonging to Fluid Styled Content in folder
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 Resources/Private/PageView here.
By convention the templates of Fluid Styled Content have the name of the CType in CamelCase. Copy file
vendor/typo3/cms-fluid-styled-content/Resources/Private/Templates/MenuSubpages.html
into folder 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:
In most parts the changes we made are pretty straight forward. In line 9
we use the Fluid inline notation
of the If ViewHelper <f:if> to only
output class active if the page in the menu is in the root line.
Override the sitemap template
In a similar fashion we now copy and adjust the template for the sitemap from
vendor/typo3/cms-fluid-styled-content/Resources/Private/Templates/MenuSitemap.html
into folder packages/site_package/Resources/Private/ContentElements/Templates/MenuSitemap.html
and then adjust it:
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 Render ViewHelper <f: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.
The templates of some content elements use the
Render ViewHelper <f: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:
Which contains another until we finally arrive at
vendor/typo3/cms-fluid-styled-content/Resources/Private/Partials/Media/Rendering/Image.html
which does contain the actual Media ViewHelper <f: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:
The site package you generated in step
Generate a site package
comes with two content elements. We look at the more basic content elements first.
You can now replace the content element in the area "Stage" of start page with
one of type "Jumbotron".
The new Content Blocks "Jumbotron" and "Carousel"
You can now create a jumbotron with a button and a link.
Directory packages/my_site_package/ContentBlocks/ContentElements contains
one directory for each Content Block that can be used as normal Content Elements.
Directory structure of a Content Block
A Content Block consists of a configuration (config.yaml), a template and
optionally assets and or language files:
File packages/my_site_package/ContentBlocks/ContentElements/jumbotron/config.yaml
defines what fields should be available for the Content Block in the backend:
Line 3: The values of the database entry of the current content element can be
found in variable {data}. In this line we render the content of the field
header. The field was defined in line 8 of the config.yaml.
Line 4: Here we output the content of field bodytext as this field is a
Rich-Text Editor we use the
Format.html ViewHelper <f:format.html>
to format and sanitize the output.
The carousel Content block is provided in the generated site package as an
example on how to create a content block that contains on repeated items, here a
carousel with multiple slides.
Directory structure of the carousel content element
Additionally to the files that the jumbotron provides (compare
Directory structure of a Content Block), the carousel comes with special CSS
and JavaScript needed for this element only.
Additionally it supplies a template for its display in the backend.
Line 8: We use a field of type
Collection
to contain the items to be displayed in the carousel. This field type expects
an array of fields (line 10ff).
Line 15: We use the type
File
to reference the image for the carousel item. We allow images only (line 16)
and require exactly one image (lines 17 and 18).
Line 20: The title should be one line of text. We use the type
Text.
Line 22: The description may contain rich text. Therefore, we use the type
Textarea
and enable the Rich-Text Editor (line 23).
Frontend template: Fluid template for a Content Block with a Collection
Line 1: We use Asset.css ViewHelper <f:asset.css>
to load the provided CSS file only if a carousel is displayed on that page. The
Asset collector
takes care that the file is not loaded more then once per page. All Fluid
ViewHelpers prefixed with cb: are provided by
friendsoftypo3/content-blocks
they are therefore not listed in the official View Helper reference. The inline
ViewHelper cb:assetPath() resolves paths to the asset folder of the current
content block.
Line 6: We use the For ViewHelper <f:for>
to loop through each item. We then render a button for each carousel item.
Line 11: We loop the items a second time to now display all carousel slides.
Line 13: The field image was defined with option relationship: manyToOne in
the config.yaml it can therefore only contain
one image at maximum. As supplying an image is also mandatory minitems: 1
we can be sure there is always exactly one image. And just use the
Image ViewHelper <f:image>
to display the image.
Line 16: As the field {item.description} is of type Textarea with rich-text
enabled we have to use the Format.html ViewHelper <f:format.html>
to properly display it.
Line 23, 27: The previous and next buttons use localized text for their labels.
We use the Translate ViewHelper <f:translate>
to translate these labels and a view helper provided by the Content Block
extension to determine the path to the language file.
Content Block with backend template
This Content Block contains a template to influence how the content elements
should be displayed in the TYPO3 backend in the Page module:
The same fields like for the frontend template are available and the same
ViewHelpers can be used. However we display them in a simplified form.
Line 1: We are using the layout Preview, which already gives some structure to
the display of the backend element:
The sections of a content element backend layout: (1) Header, (2) Content, (3) Footer
The line on the very top with the name of the content element, the icon and the
edit buttons is generated by TYPO3 automatically and cannot be influenced by
a backend template. It uses the label title defined in language/labels.xlf
and the icon assets/icon.svg.
The assets in folder assets can be loaded in the
Frontend Template. They will only be loaded when the
Content Block is loaded on the current page. If compression
(config.compressCss,
config.compressJs) and concatenation
(config.concatenateCss,
concatenateJs) are enabled
all assets are compressed and concatenated into as few as possible small asset
files.
This also has the advantage that your JavaScript is only loaded if needed.
You can use the Site Package Builder to
create a customized site package. If you want to follow this tutorial, choose
"Site Package Tutorial" as base package.
What files are included in a site package?
A site package typically includes the following files:
Configuration files, such as site settings, TypoScript, and RTE
(rich-text editor) configurations
Public assets: CSS, JavaScript, fonts, theme related images
Templates: Fluid templates that generate the HTML output
If you are developing functionality that may need to be shared across multiple sites
or TYPO3 installations in the future, it is advisable to create a
custom extension
for that functionality instead.
The site package extension, as it stands now, still has some shortfalls. Let us
have a closer look what you could or should do as the next steps to address
these.
Navigation menu features one level only
The bigger the website becomes, the more likely is a multi-level page
structure required. This means, editors will likely create sub-pages of the
root page "Page 1" for example. At the moment, the menu does not support
sub-pages.
If this becomes a requirement, the TypoScript code used to generate the menu
(see chapter TypoScrip configuration of the main menu) and the Fluid template file that
outputs the menu (Resources/Private/Layouts/Page/Default.html) need
to be updated.
The Stage stands as a place holder for various options in our example.
Some readers may like to implement a banner with rotating images, some prefer a
text content element or a video player instead. All this and much more is
possible with TYPO3, but beyond the scope of this tutorial.
There are no icons for pages in the menu
It would be possible to define an additional field in the
pages
table to store an icon for each page and then output them in the menu for
example.
There is not footer
The page could receive a footer with content taken from a special page or
column of the root page.
In general, the nature of a tutorial, such as this document, is to provide
detailed instructions to walk a beginner through a particular task. By building
your own site package extension from scratch, you have learned each step that
is required to turn a basic web design template into a fully working website in
TYPO3.
When you create site packages in the future, you probably do not want to create
every file over and over again, but use a pre-built version of the site package
extension. Therefore, it make sense to store and maintain the current state in
a central place, such as a Git repository. Despite the fact that for a learning
experience it is always beneficial to develop the extension yourself, you can
also download the extension built in this tutorial below.