Checking templates for errors
New in version Fluid 5.3
The console command fluid analyze parses Fluid templates without rendering
them. It reports what it finds:
- a syntax error, for example ViewHelper tags that are nested wrongly
- a ViewHelper or a ViewHelper namespace that does not resolve
- a variable name that starts with an underscore
- a deprecated ViewHelper or ViewHelper argument, if the deprecation is triggered while the template is parsed, see Deprecating a ViewHelper or an argument
Tip
TYPO3 provides its own command for this purpose, which can resolve available templates, global ViewHelpers and components automatically, see Check templates with the Fluid analyser.
Checking the templates in a directory
Pass one or more directories with the argument --. Separate several
directories with spaces:
./vendor/bin/fluid analyze --path templates/ partials/
The command checks the files with the file extension *. in these
directories and their subdirectories. To check other files, name their file
extension with the argument --:
./vendor/bin/fluid analyze --path templates/ --extension html
To check a single file, use the argument -- instead of --:
./vendor/bin/fluid analyze --template templates/List.fluid.html
The argument -- cannot be combined with -- or --.
Reading the result
The command writes each finding with the path of the template and the message. The lines of the following example are wrapped:
[ERROR] templates/List.fluid.html: Fluid parse error in template
templates/List.fluid.html, line 4 at character 1. Error: Variable
identifiers cannot start with a "_": _temp (error code 1765900762).
Template source chunk: {_temp}
[DEPRECATION] templates/Detail.fluid.html: <my:obsolete> is deprecated
and will be removed in version 6.
The parser stops at the first error in a template. Therefore, the command reports at most one error per template. Fix the error and run the command again to find the next one.
The command ends with the exit code 0, also if it reports an error. To
stop a continuous integration pipeline on an error, check the output of the
command.
Checking a template from another tool
With the argument --, the command reads one template from the
standard input instead of a file. The file extension does not matter then.
With the argument --, the command writes its result as JSON, including
the line and the character of each error. Editors and Git hooks can use both
arguments to check a single template:
./vendor/bin/fluid analyze --stdin --json < templates/List.fluid.html