We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Setting stylesheet/javascript in controller?

Is this possible to set css stylesheet or javascript in controller or I have to set variable in controller and then in views use tag service??

edited Mar '14

Yes you can:

class IndexController extends \Phalcon\Mvc\Controller {
    public function IndexAction()
    <?= $custom_1 ?>
    <!-- or ->
    <?php echo $this->tag->stylesheetLink($custom_2); ?>


You can use collection from Phalcon

$this->assets ->collection('styles')

and in view

    <meta charset="utf-8">
    {{ assets.outputCss('styles') }}

and you can add any css (or js) in any actions

function someAction() {

By the way, all of this you can find in documentaion.

edited Mar '14

from 1.2.5 and up.


My mistake, i didn't verify it in the changelog and it has been added in 1.1.0.


Please watch your tone Oleg, i'd like to think we have a nice community of people here just wanting to help other people. Keep it friendly and professional.

edited Mar '14

Please accept my apologies. I just wanted to point out a careful inspection of docs. :)

I have long been using this functionality from Phalcon

edited Mar '14

D/W man it's cool. It just forces me to go ahead and create some pull requests.

I've added assets to the controller stubs so that it's easier to access them from the controller in an IDE.


i also updated the documentation to reflect volt syntax.