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

Checking the templates in a directory 

Pass one or more directories with the argument --path. Separate several directories with spaces:

./vendor/bin/fluid analyze --path templates/ partials/
Copied!

The command checks the files with the file extension *.fluid.* in these directories and their subdirectories. To check other files, name their file extension with the argument --extension:

./vendor/bin/fluid analyze --path templates/ --extension html
Copied!

To check a single file, use the argument --template instead of --path:

./vendor/bin/fluid analyze --template templates/List.fluid.html
Copied!

The argument --template cannot be combined with --path or --extension.

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.
Copied!

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 --stdin, the command reads one template from the standard input instead of a file. The file extension does not matter then. With the argument --json, 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
Copied!