Creative Commons License
This work is licensed under a
Creative Commons
Attribution-Share Alike 3.0
Unported License.

Master Symfony2 fundamentals

Be trained by SensioLabs experts (2 to 6 day sessions -- French or English).
trainings.sensiolabs.com

Discover the SensioLabs Support

Access to the SensioLabs Competency Center for an exclusive and tailor-made support on Symfony
sensiolabs.com

Documentation Format

The Symfony2 documentation uses reStructuredText as its markup language and Sphinx for building the output (HTML, PDF, ...).

reStructuredText

reStructuredText "is an easy-to-read, what-you-see-is-what-you-get plaintext markup syntax and parser system".

You can learn more about its syntax by reading existing Symfony2 documents or by reading the reStructuredText Primer on the Sphinx website.

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 adds some nice tools to create documentation from reStructuredText documents. As such, it adds new directives and interpreted text roles to the standard reST markup.

Syntax Highlighting

All code examples uses PHP as the default highlighted language. You can change it with the code-block directive:

1
2
3
.. code-block:: yaml

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

If your PHP code begins with <?php, then you need to use html+php as the highlighted pseudo-language:

1
2
3
.. code-block:: html+php

    <?php echo $this->foobar(); ?>

Note

A list of supported languages is available on the Pygments website.

Configuration Blocks

Whenever you show a configuration, you must use the configuration-block directive to show the configuration in all supported configuration formats (PHP, YAML, and XML)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
.. 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
    1
    # Configuration in YAML
    
  • XML
    1
    <!-- Configuration in XML -->
    
  • PHP
    1
    // Configuration in PHP
    

The current list of supported formats are the following:

Markup format Displayed
html HTML
xml XML
php PHP
yaml YAML
jinja Twig
html+jinja Twig
html+php PHP
ini INI
php-annotations Annotations
php-standalone Standalone Use
php-symfony Framework Use

Testing Documentation

To test documentation before a commit:

  • Install Sphinx;
  • Install the Sphinx extensions using git submodules: git submodule update --init;
  • (Optionally) Install the bundle docs and CMF docs: bash install.sh;
  • Run make html and view the generated HTML in the build directory.