A specific stylesheet for each module
By Geoffrey on Wednesday 15 October 2008, 00:43 - Symfony - Permalink
Tags :
So this is the first post of the newly opened symfony category of this blog, and I want to make things clear right now: you (most likely) won't find (yet) any protip or high level symfony tutorials here, as I'm still in the process of learning symfony. The good news though is that I'm currently assigned an 1.2-DEV project, so you may get some insight at what's up in the dev branch of the framework (especially regarding sfForm) :-)
If your are looking for more complete material on the subject, please redirect yourself to the official website (where you can find the documentation and a very interesting blog) or Fabien's blog.
That said, I think it could be interesting to post all the little things I learn everyday that make development with symfony easier for the everyday php developper that you might be if you made it this far into this post ;-)
Soooo, let's begin the show, with some yaml magic. Yaml I said ? Yaml I said. For those not knowing yet, yaml is the format of choice for symfony's configurations file. So what's the point between configuration files and stylesheets ? Let's say you've got a symfony application (say, frontend), and you'd like a particular module (say, news) in this application to have its own stylesheet in addition of the defaults stylesheets you defined already. Very simple, you start by creating the adequate configuration file:
cd apps/frontend/modules/news/ mkdir config vi config/view.yml
All you have to do know is declare the stylesheet:
all: stylesheets: [news]
And that's all, no helper call in the layout, your news.css will automagically be appended to the <head> of your generated html. You can also declare multiples css, or control which actions get a particular css, and even specify to which media they apply:
all:
stylesheets: [news, news_print: { media: print }]
list:
stylesheets: [list]
Handy, heh.
But that's not all ! If you're not that much into yaml, you can use a view helper, directly into your template:
<?php use_stylesheet('news'); ?>
Or even add it from the controller:
<?php $this->getResponse()->addStylesheet('news'); ?>
3 comments
So you quit developing on ZF ? Was it by choice or did it occur by the arrival of your new project ?
I coded a few things myself on ZF, but everybody around tell me Symphony is much fun ;)
You might have missed it since I wrote the post in french, but I am now working for sensio labs, the creators of symfony, so as a matter of fact, most of my work will now be symfony-based :-)
But it was also a choice before that to drop ZF, and I will soon post an entry on why
Oh yeah, I actually missed that post ;)
This post's comments feed