Exploring view.yml features
A little research on what kind of features does view.yml support in symfony.
I have long wanted all css and js files to be connected in one place. Due to the fact that I constantly use conditional comments to separate “godly” browsers, I had to store all the files directly in the template. In the event that there are several templates, problems from the category of “added there, forgotten here” began. Therefore, it was decided to delve into the bowels of symfony, the benefit in changelog to 1.2 in white is written: support for conditional comments has been added.
And, which is characteristic, all this is. Only it is not clear why not a word is said about this in the symfony documentation. Apparently, due to the ugliness of the resulting yml.
All this is generated here in such a PHP array:
Why such difficulties, you ask, when you can and like this:
I also believed that it was possible. Here the yaml handler felts bug pops up, sfViewConfigHandler felts, resulting in Fatal Error.
In short, while all this smacks of hack, and, apparently, that’s why this is all not documented.
I have long wanted all css and js files to be connected in one place. Due to the fact that I constantly use conditional comments to separate “godly” browsers, I had to store all the files directly in the template. In the event that there are several templates, problems from the category of “added there, forgotten here” began. Therefore, it was decided to delve into the bowels of symfony, the benefit in changelog to 1.2 in white is written: support for conditional comments has been added.
What would you like to see?
- Support for conditional comments for IE;
- Support for media devices in CSS;
- The ability to change the position of the connected libraries relative to each other.
And, which is characteristic, all this is. Only it is not clear why not a word is said about this in the symfony documentation. Apparently, due to the ugliness of the resulting yml.
stylesheets: [{main.ie.css: {position: 'last', condition: 'lt IE 8', media: 'screen'}}, {frontend.css: {position: 'first', media: 'screen'}}]
What the heck is that?:)
All this is generated here in such a PHP array:
$ stylesheets = array ( array ('main.ie.css' => array ('position' => 'last', 'condition' => 'lt IE 8', 'media' => 'screen')), array ('frontend.css' => array ('position' => 'first', 'media' => 'screen')) );
Why such difficulties, you ask, when you can and like this:
$ stylesheets = array ( 'main.ie.css' => array ('position' => 'last', 'condition' => 'lt IE 8', 'media' => 'screen'), 'frontend.css' => array ('position' => 'first', 'media' => 'screen') );
I also believed that it was possible. Here the yaml handler felts bug pops up, sfViewConfigHandler felts, resulting in Fatal Error.
In short, while all this smacks of hack, and, apparently, that’s why this is all not documented.
But still, what does all this mean?
- main.ie.css - obviously this is the name of the include file.
- position - The position of the library relative to the rest. It can be either first or last. In my opinion, it’s worth not to show off and just indicate the libraries in the exact order in which they need to be connected.
- condition - The condition for the conditional comment. Obviously, if this key is not specified, conditional comments will not be used. For details on the syntax of conditional comments on MSDN.
- media - type of device. For details about device types, see the CSS documentation.
That's all, actually :)
PS Yes, I will be happy if someone tells me how to make the code highlight.
PPS research was conducted on symfony 1.2.8