Caution: You are browsing the legacy Logo of the legacy symfony 1 version 1.x part of this website.
This version of symfony is not maintained anymore. If some of your projects still use this version, consider upgrading.

Master Symfony fundamentals

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

Discover SensioLabs' Professional Business Solutions

Peruse our complete Symfony & PHP solutions catalog for your web development needs.
sensiolabs.com
The Reference Book

The View layer can be configured by editing the view.yml configuration file.

As discussed in the introduction, the view.yml file benefits from the configuration cascade mechanism, and can include constants.

caution

This configuration file is mostly deprecated in favors of helpers used directly in the templates or methods called from actions.

The view.yml configuration file contains a list of view configurations:

VIEW_NAME_1:
  # configuration
 
VIEW_NAME_2:
  # configuration
 
# ...

note

The view.yml configuration file is cached as a PHP file; the process is automatically managed by the sfViewConfigHandler class.

Layout

Default configuration:

default:
  has_layout: true
  layout:     layout

The view.yml configuration file defines the default layout used by the application. By default, the name is layout, and so symfony decorates every page with the layout.php file, found in the application templates/ directory. You can also disable the decoration process altogether by setting the ~has_layout~ entry to false.

tip

The layout is automatically disabled for XML HTTP requests and non-HTML content types, unless explicitly set for the view.

Stylesheets

Default Configuration:

default:
  stylesheets: [main.css]

The stylesheets entry defines an array of stylesheets to use for the current view.

note

The inclusion of the stylesheets defined in view.yml can be done with the include_stylesheets() helper.

If many files are defined, symfony will include them in the same order as the definition:

stylesheets: [main.css, foo.css, bar.css]

You can also change the media attribute or omit the .css suffix:

stylesheets: [main, foo.css, bar.css, print.css: { media: print }]

This setting is deprecated in favor of the use_stylesheet() helper:

<?php use_stylesheet('main.css') ?>

note

In the default view.yml configuration file, the referenced file is main.css, and not /css/main.css. As a matter of fact, both definitions are equivalent as symfony prefixes relative paths with /css/.

JavaScripts

Default Configuration:

default:
  javascripts: []

The javascripts entry defines an array of JavaScript files to use for the current view.

note

The inclusion of the JavaScript files defined in view.yml can be done with the include_javascripts() helper.

If many files are defined, symfony will include them in the same order as the definition:

javascripts: [foo.js, bar.js]

You can also omit the .js suffix:

javascripts: [foo, bar]

This setting is deprecated in favor of the use_javascript() helper:

<?php use_javascript('foo.js') ?>

note

When using relative paths, like foo.js, symfony prefixes them with /js/.

Metas and HTTP Metas

Default Configuration:

default:
  http_metas:
    content-type: text/html
 
  metas:
    #title:        symfony project
    #description:  symfony project
    #keywords:     symfony, project
    #language:     en
    #robots:       index, follow

The http_metas and metas settings allows the definition of meta tags to be included in the layout.

note

The inclusion of the meta tags defined in view.yml can be done manually with the include_metas() and include_http_metas() helpers.

These settings are deprecated in favor of pure HTML in the layout for static metas (like the content type), or in favor of a slot for dynamic metas (like the title or the description).

tip

When it makes sense, the content-type HTTP meta is automatically modified to include the charset defined in the settings.yml configuration file if not already present.