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 plaintext 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

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

警告

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 reST 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:

.. code-block:: yaml

    { foo: bar, bar: { foo: bar, bar: baz } }

注解

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:

.. configuration-block::

    .. code-block:: yaml

        # Configuration in YAML

    .. code-block:: xml

        <!-- Configuration in XML -->

    .. code-block:: php

        // Configuration in PHP

The previous reST snippet renders as follow:

  • YAML
    # Configuration in YAML
    
  • XML
    <!-- Configuration in XML -->
    
  • PHP
    // Configuration in PHP
    

The current list of supported formats are the following:

Markup Format Use It to Display
html HTML
xml XML
php PHP
yaml YAML
jinja Pure Twig markup
html+jinja Twig markup blended with HTML
html+php PHP code blended with HTML
ini INI
php-annotations PHP Annotations

New Features or Behavior Changes

If you’re documenting a brand new feature or a change that’s been made in Symfony, you should precede your description of the change with a .. versionadded:: 2.X directive and a short description:

.. versionadded:: 2.3
    The ``askHiddenResponse`` method was introduced in Symfony 2.3.

You can also ask a question and hide the response. This is particularly [...]

If you’re documenting a behavior change, it may be helpful to briefly describe how the behavior has changed.

.. versionadded:: 2.3
    The ``include()`` function is a new Twig feature that's available in
    Symfony 2.3. Prior, the ``{% include %}`` tag was used.

Whenever a new minor version of Symfony is released (e.g. 2.4, 2.5, etc), a new branch of the documentation is created from the master branch. At this point, all the versionadded tags for Symfony versions that have reached end-of-life will be removed. For example, if Symfony 2.5 were released today, and 2.2 had recently reached its end-of-life, the 2.2 versionadded tags would be removed from the new 2.5 branch.

Testing Documentation

When submitting a new content to the documentation repository or when changing any existing resource, an automatic process will check if your documentation is free of syntax errors and is ready to be reviewed.

Nevertheless, if you prefer to do this check locally on your own machine before submitting your documentation, follow these steps:

  • Install Sphinx;
  • Install the Sphinx extensions using git submodules: $ git submodule update --init;
  • Run make html and view the generated HTML in the build/ directory.