Twig for TYPO3 CMS 

Extension key

cvc_twig

Version

1.0.0

Language

en

Description

This extension integrates the Twig template engine into TYPO3 CMS.

Keywords

layout, frontend, template engine

Copyright

CARL von CHIARI GmbH

Author

CARL von CHIARI GmbH

License

GNU General Public License, either version 3 of the License or any later version.

Rendered

Tue, 27 Jan 2026 15:33:30 +0000

This project aims to integrate the Twig template engine as a feature complete replacement for Fluid.

Table Of Content 

Installation 

This extension only works when installed in composer mode. If you are not familiar using composer together with TYPO3 yet, you can find a how to on the TYPO3 website.

Install the extension with the following command:

composer require cvc/typo3-twig
Copied!

Getting started 

Rendering of Twig templates works nearly exactly the same way as rendering Fluid templates.

In contrast to Fluid there are no "layouts" nor "partials" in Twig. Everything is "just" a template. Therefore there are some features missing that you are probably used by Fluid.

Render templates in TypoScript 

To render a Twig template you can use the TWIGTEMPLATE content object.

page.10 = TWIGTEMPLATE
page.10 {
    templateName = example.html.twig
    variables {
        foo = TEXT
        foo.value = Bar!
    }
    templateRootPaths {
        10 = EXT:cvc_twig/Resources/Private/TwigTemplates/
    }
}
Copied!

Render templates in an Extbase controller 

If you want to use twig from within your controller, you just have to switch the $defaultViewObjectName to \Cvc\Typo3\CvcTwig\Extbase\Mvc\View\TwigView. See the example below.

The template file will be automatically set to @controller/@action.@format.twig. The templateRootPaths that are defined for extbase will be respected. You should not forget to configure those using TypoScript.

Given you have the following controller; you just have to set the $defaultViewObjectName to the TwigView class.

<?php

// my_extension/Classes/Controller/MyFantasticalController.php

class MyFantasticalController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
{
    // setting the default view object class to TwigView will enable the Twig templates
    protected $defaultViewObjectName = \Cvc\Typo3\CvcTwig\Extbase\Mvc\View\TwigView::class;

    public function someAwesomeAction()
    {
        // assign the variables as usual
        $this->view->assign('foo', 'BAZ!');
    }
}
Copied!

The templateRootPaths are configured using TypoScript:

plugin.tx_my_extension {
    view {
        templateRootPaths.0 = EXT:my_extension/Resources/Private/Templates/
    }
}
Copied!

The Twig template has to be placed in my_extension/Resources/Private/Templates/ and has to be named MyFantastical/someAwesome.html.twig.

{# my_extension/Resources/Private/Templates/MyFantastical/someAwesome.html.twig #}

Foo: {{ foo }}
Copied!

Twig 

Filters and functions that are provided by this extension are explained here. Of course you can also use the build in filters, functions, tags, tests and operators. You can find them in the official reference documentation.

Develop Custom Twig Extensions 

Twig allows to extend the template language by adding custom functions, filters, tags, and some more. This TYPO3 extension currently only supports to add Twig Extensions (which include all mentioned). Please read in the official Twig documentation, how to create your own extension.

To register the Twig Extension in your TYPO3 Extension, there is nothing more needed than enabling auto wiring and auto configuration in the dependency injection service configuration:

services:
_defaults:
    autowire: true
    autoconfigure: true
    public: false

Vendor\Namespace\:
    resource: '../Classes/*'
Copied!

All available Twig Extensions, that are covered by the above configuration, are automatically added to the Twig Environment.

TWIGTEMPLATE 

With this Content Object a template file (e.g. a HTML file) is rendered. The functionality is close to FLUIDTEMPLATE.

Properties 

templateName

Type string / stdWrap

The template that is used for rendering.

templateRootPaths

Type string / stdWrap

The root directories for the loader to look in.

variables

Type cObject[]

Sets variables that should be available in the Twig template. The keys are the variable names.

Reserved variable names are data and current, which are filled automatically with the current data set.

settings

Type array

Sets the given settings array in the Twig template.

dataProcessing

Type array

Add one or multiple processors to manipulate the variables that will be passed to the template engine. The sub- property options can be used to pass parameters to the processor class.

Example:

page.10 = TWIGTEMPLATE
page.10 {
    templateName = EXT:site_package/Resources/Private/TwigTemplates/template.html.twig
    dataProcessing {
        1 = Vendor\YourExtensionKey\DataProcessing\MyFirstCustomProcessor
        2 = Vendor2\AnotherExtensionKey\DataProcessing\MySecondCustomProcessor
        2.options {
            myOption = SomeValue
        }
    }
}
Copied!

The build-in data processors are documented here.

namespaces

Type array

The file loader shipped with Twig allows to register namespaced folders. A namespace can be referenced with @namespace followed by the path to the template.

Example:

page.10 = TWIGTEMPLATE
page.10 {
    templateName = @myComponents/text_and_media.html.twig
    namespaces {
        myComponents {
            10 = EXT:example_site/Private/frontend/src/components
        }
    }
}
Copied!

The given code example defines a namespace called myComponents. A template that is located in EXT:example_site/Private/frontend/src/components can be referenced using the namespace. The template name will looks like @myComponents/text_and_media.html.twig.

Functions 

dump 

{{ dump(vars) }}
Copied!

Displays the content of the variable(s) on the screen.

The dump() functions prints the contents of a variable. This is useful for debugging. Please ensure that the frontend debug mode is on, because otherwise the function does not print anything. Internally DebuggerUtility::var_dump() is used.

{# print a single variable #}
{{ dump(foo) }}

{# print multiple variables #}
{{ dump(foo, bar, baz) }}

{# print all variables #}
{{ dump() }}
Copied!

Arguments 

vars

Type: mixed

Any number of variables.

t3_cobject 

{{ t3_cobject(
    typoScriptObjectPath,
    data = null,
    currentValueKey = null,
    table = null
) }}
Copied!

Renders a TypoScript object. The content object renderer can be populated using the data argument.

Arguments 

typoScriptObjectPath
Type: string
data
Type: mixed | Default: null
currentValueKey
Type: string | Default: null
table
Type: string | Default: null

t3_form_render 

{{ t3_form_render(
    persistenceIdentifier = null,
    factoryClass = 'TYPO3\\CMS\\Form\\Domain\\Factory\\ArrayFormFactory',
    prototypeName = null,
    overrideConfiguration = []
) }}
Copied!

Renders a form using the form framework.

TwigtestContentElement.html.twig
{{ t3_form_render(settings.persistenceIdentifier) }}
Copied!

Arguments 

persistenceIdentifier

Type: string | Default: null

The identifier of the form, if a YAML file is used. If null, then a Factory class needs to be set.

factoryClass

Type: string | Default: 'TYPO3\\CMS\\Form\\Domain\\Factory\\ArrayFormFactory'

the fully qualified class name of the factory

prototypeName

Type: string | Default: null

name of the prototype to use

overrideConfiguration

Type: array | Default: []

Factory specific configuration. This will allow to add additional configuration related to the current view.

t3_uri_action 

{{ t3_uri_action(
    action,
    arguments = [],
    controller = null,
    extensionName = null,
    pluginName = null,
    pageUid = null,
    pageType = 0,
    noCache = false,
    section = '',
    format = '',
    linkAccessRestrictedPages = false,
    additionalParams = [],
    absolute = false,
    addQueryString = false,
    argumentsToBeExcludedFromQueryString = [],
    addQueryStringMethod = ''
) }}
Copied!

Arguments 

action
Type: string
arguments
Type: array | Default: []
controller
Type: string | Default: null
extensionName
Type: string | Default: null
pluginName
Type: string | Default: null
pageUid
Type: int | Default: null
pageType
Type: int | Default: 0
noCache
Type: bool | Default: false
section
Type: string | Default: ''
format
Type: string | Default: ''
linkAccessRestrictedPages
Type: bool | Default: false
additionalParams
Type: array | Default: []
absolute
Type: bool | Default: false
addQueryString
Type: bool | Default: false
argumentsToBeExcludedFromQueryString
Type: array | Default: []
addQueryStringMethod
Type: string | Default: ''

t3_uri_image 

{{ t3_uri_image(
    src = null,
    treatIdAsReference = false,
    image = null,
    crop = null,
    cropVariant = 'default',
    width = '',
    height = '',
    minWidth = 0,
    minHeight = 0,
    maxWidth = 0,
    maxHeight = 0,
    absolute = false
) }}
Copied!

Returns the URL to the given image. If an error occurs, then null is returned and no error is raised.

Arguments 

src
Type: string | Default: null
treatIdAsReference
Type: bool | Default: false
image

Type: mixed | Default: null

the image can be a reference or an instance of FileInterface or FileReference

crop

Type: string | Default: null

the JSON-formatted crop settings

cropVariant
Type: string | Default: 'default'
width
Type: string | Default: ''
height
Type: string | Default: ''
minWidth
Type: int | Default: 0
minHeight
Type: int | Default: 0
maxWidth
Type: int | Default: 0
maxHeight
Type: int | Default: 0
absolute
Type: bool | Default: false

t3_uri_model 

{{ t3_uri_model(model) }}
Copied!

Generates a link fro the given domain model.

A link handler must be configured for the mapped table.

Arguments 

model
Type: TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface

t3_uri_page 

{{ t3_uri_page(
    pageUid = null,
    additionalParams = [],
    pageType = 0,
    noCache = false,
    section = '',
    linkAccessRestrictedPages = false,
    absolute = false,
    addQueryString = false,
    argumentsToBeExcludedFromQueryString = [],
    addQueryStringMethod = ''
) }}
Copied!

Arguments 

pageUid
Type: int | Default: null
additionalParams
Type: array | Default: []
pageType
Type: int | Default: 0
noCache
Type: bool | Default: false
section
Type: string | Default: ''
linkAccessRestrictedPages
Type: bool | Default: false
absolute
Type: bool | Default: false
addQueryString
Type: bool | Default: false
argumentsToBeExcludedFromQueryString
Type: array | Default: []
addQueryStringMethod
Type: string | Default: ''

t3_uri_record 

{{ t3_uri_record(table, recordUid) }}
Copied!

Generates a link for the given record.

A link handler must be configured for the mapped table.

Arguments 

table

Type: string

the table of the record

recordUid

Type: int

the UID of the record

Filters 

:local:

t3_html 

{{ html | t3_html(parseFuncTSPath = 'lib.parseFunc_RTE') }}
Copied!

Parses HTML that was created with an rich text editor.

Arguments 

html

Type: string

The HTML that should be processed. Normally this is the content that is stored in the database.

parseFuncTSPath

Type: string | Default: 'lib.parseFunc_RTE'

here you can define which setup should be used to transform the HTML content

t3_trans 

{{ key | t3_trans(arguments = [], extensionName = null) }}
Copied!

Translates the given translation key into the active language.

Arguments 

key

Type: string

the key for the translation

arguments

Type: array | Default: []

the arguments that are replaced while translating

extensionName

Type: string | Default: null

the name of the TYPO3 extension where the translation file is located