Frontend requests
When handling frontend web requests, TYPO3 automatically sets up a rich context that is used to render content and generate links. Several objects are created and configured during this process:
- ContentObjectRenderer (cObj) – Responsible for processing TypoScript-based rendering, including typolink and other link generation tasks.
- page Attribute – Holds the current page context and is used by many rendering processes.
- PageInformation Object: Provides additional metadata about the current page.
- Router: Ensures proper URL resolution.
- FrontendTypoScriptFactory: Collects
TypoScript and provides settings like
link
andAccess Restricted Pages typolink
.Link Access Restricted Pages
These components work together only because the frontend request bootstrap initializes them with all the necessary data.
Limitations when there is no frontend request
When executing code outside of a frontend request (for example, in a CLI command), this context is missing:
- The ContentObjectRenderer (cObj)
can be instantiated manually, but it will
not have a populated
data
array because there is nott_
record. As a result, TypoScript properties likecontent field = my_
orfield data = my_
will not work as expected.data - The
Frontend
is not set up.Typo Script Factory
Understanding this difference is crucial when writing custom code that depends on frontend rendering behavior but runs in a different context.
Simulating a frontend request
It may be necessary to simulate a frontend request to make certain functionality available where it would usually not be available.
For example, you might need to simulate a frontend request to be able to send a FluidEmail from a CLI / Console command context.
To simulate a frontend request you need, at a minimum, a site. If the current site is not defined you can use the SiteFinder to find one.
The following example demonstrates how to set up a basic frontend request with
application
and site
attributes:
use TYPO3\CMS\Core\Core\Bootstrap;
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Site\SiteFinder;
$site = $this->siteFinder->getSiteByPageId(1);
$request = (new ServerRequest())
->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE)
->withAttribute('site', $site);
For a complete example on how to send a FluidEmail with a console command see Example: Sending a FluidEmail via console command.
At this stage, the simulated frontend request still lacks page-related information and does not load TypoScript. It is still only a simplified simulation.
If you rely on any of these methods you will need to bootstrap them before using them.
Note
There is no simple way to fully simulate a frontend request. Some aspects, like basic link generation, can work by manually setting request attributes. However, complex TypoScript-based link modifications, access restrictions, and context-aware rendering will not behave the same as a real web request.