KO3: How to deal with stylesheets and scriptfiles

Posted by Svish on Stack Overflow See other posts from Stack Overflow or by Svish
Published on 2010-05-14T15:59:19Z Indexed on 2010/05/14 21:14 UTC
Read the original article Hit count: 215

Filed under:
|
|
|

I'm using Kohana 3 and it's template controller. My main site template controller currently looks something like this:

<?php defined('SYSPATH') or die('No direct script access.');

abstract class Controller_SiteTemplate extends Controller_Template
{
    public function before()
    {
        parent::before();

        // Initialize default template variables
        $this->template->styles           = Kohana::config('site.styles');
        $this->template->scripts          = Kohana::config('site.scripts');

        $this->template->title            = '';
        $this->template->content          = '';
    }
}

And then in my template view I do:

<?php # Styles
foreach($styles as $file => $media) 
    echo HTML::style($file, array('media' => $media)).PHP_EOL ?>

<?php # Scripts
foreach($scripts as $file) 
    echo HTML::script($file).PHP_EOL ?>

This works alright. The problem is that it requires the style- and script files to be added in the controller, which shouldn't really have to care about those. It also makes it a hassle if the views are done by someone else than me since they would have to fool around with the controller just to add a new stylesheet or a new script file. How can this be done in a better way?

Just to clearify, what I am wondering is how to deal with page specific stylesheets and scripts. The default and site-wide ones I have no problem with fetching from a config file or just put directly in the template view. My issue is how to add custom ones for specific pages in a good way.

© Stack Overflow or respective owner

Related posts about kohana

Related posts about kohana-3