How do I create a global stylesheets for headers and footers?

Hi All,

Can anybody please give me some advice how I can create CSS and JS assets which can be loaded as I need it on specific controllers. I was thinking of creating a Shared service then inside this shared service create my assets and use the $this-> function in my controller to load a particular stylesheet but how exactly do I do that?

I just want to minimize code duplication as much as possible.



Hi, @rewtor thanks for the link, I did follow the documentation but now I have a follow up question :

  1. Where should i put the php file with the assets inside? Must it be in my /app folder?
  2. How does it get loaded ( bootstrapped ) into my main app?

Kind Regards

edited Sep '14

As far as I can tell this is automatically loaded by Phalcon somewhere but I'm not too sure where in the documentation. Looking at the source: I can see that it's automatically loaded if you use Phalcon\DI\FactoryDefault();

You can add an asset anywhere that has acceess to the dependency injector by using either:


as described here

and just add either of the below in the bottom of your footer/layout and just make sure it's before </body>:

{{ assets.outputJs() }}
{{ assets.outputCss() }}

edited Sep '14

Where should i put the php file with the assets inside

assets are css and js. You should put them in public folder. Also check here


Hi everyone, thanks so much for the feedback, much appreciated!