Header injecting?

Hey all,

I occasionally face this problem: I need different assets on different pages and don’t want to load them all initially in order to get fast page load speeds.

I worked around that with different header snippets but that’s just unpleasant to maintain. In OctoberCMS (which i used prior to switching to kirby) there was a tag called “puthead” which basically “injected” an additional CSS or a JS into the HTML head section without having to alter the head snippet.

Is there a way to achieve this same thing in kirby?

You can use the auto loader function:

<?php echo css('@auto') ?>

Template specific css files must be located in /assets/css/templates and named like the template.

http://getkirby.com/docs/cheatsheet/helpers/css

The same works for javascript files.

Have a look at this post for other methods: How to call a javascript only for specific page/template

1 Like

is it possible to use @auto together with my standards like styles.css and main.js for example?
Can I put both in an array?

You should be able to do something like this, haven’t tested this though:

<?php echo css(array(
  'assets/css/styles,css',
  '@auto'
)) ?>

Other than that, you could of course put two lines:

<?php
echo css('assets/css/styles.css');
echo css('@auto');
?>

@bogus:
For your question, I have developed an approach some time ago.
Look at the concerning HowTo.