The symfony Reference Book

The view.yml Configuration File

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


About

You are currently reading "The symfony Reference Book" which is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported License license.

Master symfony

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

Books on symfony

Learn more about symfony with the official guides.
books.sensiolabs.com

L'audit Qualité par SensioLabs

200 points de contrôle de votre applicatif web.
audit.sensiolabs.com

Chapter Content

Layout

Stylesheets

JavaScripts

Metas and HTTP Metas

symfony training
Be trained by symfony experts
Feb 21: Köln (Getting Started with Symfony2 - English)
Feb 27: Köln (Mastering Symfony2 - English)
Mar 05: Köln (Web Development with Symfony2 - Deutsch)
Mar 05: Montreal (Web Development with Symfony2 - English)
Mar 05: Montreal (Getting Started with Symfony2 - English)
and more...

Search


powered by google
You are currently browsing "The symfony Reference Book" in English for the 1.2 version - Switch to version: - Switch to language:
Creative Commons License This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.
This version of symfony is not maintained anymore.
If some of your projects still use this version, consider upgrading as soon as possible.
The symfony reference guide
Support symfony!
Buy this book
or donate.
Buy The symfony reference guide from amazon.com

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.yml configuration file is cached as a PHP file; the process is automatically managed by the sfViewConfigHandler class.

Layout

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.

Stylesheets

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.yml can be done either manually with the include_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.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.

The inclusion of the JavaScript files defined in view.yml can be done either manually with the include_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/.

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.

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).

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.

Other Configuration Files »
« The filters.yml Configuration File

Questions & Feedback

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.