Note that there are some explanatory texts on larger screens.

plurals
  1. POKO3: How to deal with stylesheets and scriptfiles
    text
    copied!<p>I'm using Kohana 3 and it's template controller. My main site template controller currently looks something like this:</p> <pre><code>&lt;?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-&gt;template-&gt;styles = Kohana::config('site.styles'); $this-&gt;template-&gt;scripts = Kohana::config('site.scripts'); $this-&gt;template-&gt;title = ''; $this-&gt;template-&gt;content = ''; } } </code></pre> <p>And then in my template view I do:</p> <pre><code>&lt;?php # Styles foreach($styles as $file =&gt; $media) echo HTML::style($file, array('media' =&gt; $media)).PHP_EOL ?&gt; &lt;?php # Scripts foreach($scripts as $file) echo HTML::script($file).PHP_EOL ?&gt; </code></pre> <p>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?</p> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload