![]() |
|
The symfony Reference BookThe view.yml Configuration File |
|
You are currently reading "The symfony Reference Book" which is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported License license.

|
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. |
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.
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 # ...
The
view.ymlconfiguration file is cached as a PHP file; the process is automatically managed by thesfViewConfigHandlerclass.
Default configuration:
default: has_layout: on 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.
The layout is automatically disabled for XML HTTP requests and non-HTML content types, unless explicitly set for the view.
Default Configuration:
default: stylesheets: [main.css]
The stylesheets entry defines an array of stylesheets to use for the current
view.
The inclusion of the stylesheets defined in
view.ymlcan be done either manually with theinclude_stylesheets()helper, or automatically with the common filter.
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') ?>
In the default
view.ymlconfiguration file, the referenced file ismain.css, and not/css/main.css. As a matter of fact, both definitions are equivalent as symfony prefixes relative paths with/css/.
Default Configuration:
default: javascripts: []
The javascripts entry defines an array of JavaScript files to use for the
current view.
The inclusion of the JavaScript files defined in
view.ymlcan be done either manually with theinclude_javascripts()helper, or automatically with the common filter.
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') ?>
When using relative paths, like
foo.js, symfony prefixes them with/js/.
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.
The inclusion of the meta tags defined in
view.ymlcan be done manually with theinclude_metas()andinclude_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).
When it makes sense, the
content-typeHTTP meta is automatically modified to include the charset defined in thesettings.ymlconfiguration file if not already present.
If you find a typo or an error, please register and open a ticket.
If you need support or have a technical question, please post to the official user mailing-list.