We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Different css resources in layouts

I would like to split my website to two area "Admin area" and "User ares", and the two areas should use different css files.My approach is as following:

{# path : /app/views/layouts/user.volt #}

<?php
    $this->assets
            ->addCss('css/bootstrap.css')
            ->addCss('css/user.css');
?>

<div id="container">
    {{ content() }}
</div>
{# path : /app/views/layouts/admin.volt #}

<?php
    $this->assets
            ->addCss('css/bootstrap.css')
            ->addCss('css/admin.css');
?>

<div id="container">
    {{ content() }}
</div>
{# path : /app/views/index.volt #}

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Foo</title>
    {{ this.assets.outputCss() }}
</head>
<body>
    {{ content() }}
</body>
</html>

Is this a good approach? Or there is better one?



8.1k

You are completely free to use assets collections in any action of any controllers in any combinations of assets :)



1.2k

Thanks for your response. But I am curious about the side effect when I use assets collections in my layouts view rather than action of a controller.