Documentation Format

Documentation Format

The Symfony documentation uses reStructuredText as its markup language and Sphinx for generating the documentation in the formats read by the end users, such as HTML and PDF.

reStructuredText

reStructuredText is a plain text markup syntax similar to Markdown, but much stricter with its syntax. If you are new to reStructuredText, take some time to familiarize with this format by reading the existing Symfony documentation source code.

If you want to learn more about this format, check out the reStructuredText Primer tutorial and the reStructuredText Reference.

Caution

If you are familiar with Markdown, be careful as things are sometimes very similar but different:

  • Lists starts at the beginning of a line (no indentation is allowed);
  • Inline code blocks use double-ticks (``like this`` ).

Sphinx

Sphinx is a build system that provides tools to create documentation from reStructuredText documents. As such, it adds new directives and interpreted text roles to the standard reStructuredText markup. Read more about the Sphinx Markup Constructs.

Syntax Highlighting

PHP is the default syntax highlighter applied to all code blocks. You can change it with the code-block directive:

  1. .. code-block:: yaml
  2. { foo: bar, bar: { foo: bar, bar: baz } }

Note

Besides all of the major programming languages, the syntax highlighter supports all kinds of markup and configuration languages. Check out the list of supported languages on the syntax highlighter website.

Configuration Blocks

Whenever you include a configuration sample, use the configuration-block directive to show the configuration in all supported configuration formats (PHP, YAML and XML). Example:

  1. .. configuration-block::
  2. .. code-block:: yaml
  3. # Configuration in YAML
  4. .. code-block:: xml
  5. <!-- Configuration in XML -->
  6. .. code-block:: php
  7. // Configuration in PHP

The previous reStructuredText snippet renders as follow:

  • YAML

    1. # Configuration in YAML
  • XML

    1. <!-- Configuration in XML -->
  • PHP

    1. // Configuration in PHP

The current list of supported formats are the following:

Markup FormatUse It to Display
htmlHTML
xmlXML
phpPHP
yamlYAML
twigPure Twig markup
html+twigTwig markup blended with HTML
html+phpPHP code blended with HTML
iniINI
php-annotationsPHP Annotations

The most common type of links are internal links to other documentation pages, which use the following syntax:

  1. :doc:`/absolute/path/to/page`

The page name should not include the file extension (.rst). For example:

  1. :doc:`/controller`
  2. :doc:`/components/event_dispatcher`
  3. :doc:`/configuration/environments`

The title of the linked page will be automatically used as the text of the link. If you want to modify that title, use this alternative syntax:

  1. :doc:`Doctrine Associations </doctrine/associations>`

Note

Although they are technically correct, avoid the use of relative internal links such as the following, because they break the references in the generated PDF documentation:

  1. :doc:`controller`
  2. :doc:`event_dispatcher`
  3. :doc:`environments`

Links to the API follow a different syntax, where you must specify the type of the linked resource (class or method):

  1. :class:`Symfony\\Component\\Routing\\Matcher\\ApacheUrlMatcher`
  2. :method:`Symfony\\Component\\HttpKernel\\Bundle\\Bundle::build`

Links to the PHP documentation follow a pretty similar syntax:

  1. :phpclass:`SimpleXMLElement`
  2. :phpmethod:`DateTime::createFromFormat`
  3. :phpfunction:`iterator_to_array`

New Features, Behavior Changes or Deprecations

If you are documenting a brand new feature, a change or a deprecation that’s been made in Symfony, you should precede your description of the change with the corresponding directive and a short description:

For a new feature or a behavior change use the .. versionadded:: 4.x directive:

  1. .. versionadded:: 4.2
  2. Named autowiring aliases have been introduced in Symfony 4.2.

If you are documenting a behavior change, it may be helpful to briefly describe how the behavior has changed:

  1. .. versionadded:: 4.2
  2. Support for ICU MessageFormat was introduced in Symfony 4.2. Prior to this,
  3. pluralization was managed by the ``transChoice`` method.

For a deprecation use the .. deprecated:: 4.x directive:

  1. .. deprecated:: 4.2
  2. Not passing the root node name to ``TreeBuilder`` was deprecated in Symfony 4.2.

Whenever a new major version of Symfony is released (e.g. 5.0, 6.0, etc), a new branch of the documentation is created from the master branch. At this point, all the versionadded and deprecated tags for Symfony versions that have a lower major version will be removed. For example, if Symfony 5.0 were released today, 4.0 to 4.4 versionadded and deprecated tags would be removed from the new 5.0 branch.

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.