# Generate css file on panel update

**URL:** <https://forum.getkirby.com/t/generate-css-file-on-panel-update/7351>\
**Category:** Questions\
**Tags:** v2\
**Created:** [April 28, 2017, 1:45pm UTC](https://forum.getkirby.com/t/generate-css-file-on-panel-update/7351 "2017-04-28T13:45:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mthiebou](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/mthiebou/32/10284_2.png) [@mthiebou](https://forum.getkirby.com/u/mthiebou)\
**Post date:** [April 28, 2017, 1:45pm UTC](https://forum.getkirby.com/t/generate-css-file-on-panel-update/7351/1 "2017-04-28T13:45:41Z")

</div>

Hello,

Is it possible to create a css file on a panel page update hook?

Ideal solution:

After you picked some colors in the panel, you click save and a new css is generated with those colors.

Cheers, Maarten

---

<div class="post-metadata">

**Author:** ![Svnt](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/svnt/32/620_2.png) [@Svnt](https://forum.getkirby.com/u/Svnt)\
**Post date:** [April 28, 2017, 2:32pm UTC](https://forum.getkirby.com/t/generate-css-file-on-panel-update/7351/2 "2017-04-28T14:32:16Z")

</div>

Should be possible. Kirby Panel supports hooks: [https://getkirby.com/docs/developer-guide/advanced/hooks](https://getkirby.com/docs/developer-guide/advanced/hooks)

---

<div class="post-metadata">

**Author:** ![Perry](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/perry/32/1336_2.png) [@Perry](https://forum.getkirby.com/u/Perry)\
**Post date:** [April 28, 2017, 10:44pm UTC](https://forum.getkirby.com/t/generate-css-file-on-panel-update/7351/3 "2017-04-28T22:44:46Z")

</div>

Why not with CSS inline  
[https://www.w3schools.com/html/html\_css.asp](https://www.w3schools.com/html/html_css.asp)

`<h1 style=<?php echo $page->h1_color() ?>> Heading</h1>`

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [April 28, 2017, 10:55pm UTC](https://forum.getkirby.com/t/generate-css-file-on-panel-update/7351/4 "2017-04-28T22:55:52Z")

</div>

What is your use case? Maybe you could place that code within style tags in the header instead of creating a new file to avoid another http request? I guess those styles should overwrite existing styles?

---

<div class="post-metadata">

**Author:** ![mthiebou](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/mthiebou/32/10284_2.png) [@mthiebou](https://forum.getkirby.com/u/mthiebou)\
**Post date:** [April 30, 2017, 10:24am UTC](https://forum.getkirby.com/t/generate-css-file-on-panel-update/7351/5 "2017-04-30T10:24:33Z")

</div>

Hello guys,

Thank you for the suggestions.

Just searching for a way to have full control over css files.

1. Inline css is good, when you have a few styles to override.

2. If you use a dynamic css php file you can adjust each style. The problem is, each time its calculated. So the file is not cached.

3. Ideal to use a dynamic less php file, that outputs a css file only with a panel hook update.

Need some help for the last solution…

Cheers, Maarten

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [April 30, 2017, 10:29am UTC](https://forum.getkirby.com/t/generate-css-file-on-panel-update/7351/6 "2017-04-30T10:29:27Z")

</div>

I haven’t tested them but these two plugins might help:

> **[thgh/kirby-plugins](https://github.com/thgh/kirby-plugins/tree/master/less)**
>
> kirby-plugins - Plugins for Kirby CMS

  

> **[bartvandebiezen/kirby-v2-lessphp](https://github.com/bartvandebiezen/kirby-v2-lessphp)**
>
> kirby-v2-lessphp - Less plugin for Kirby 2

---

<div class="post-metadata">

**Author:** ![mthiebou](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/mthiebou/32/10284_2.png) [@mthiebou](https://forum.getkirby.com/u/mthiebou)\
**Post date:** [May 1, 2017, 4:54pm UTC](https://forum.getkirby.com/t/generate-css-file-on-panel-update/7351/7 "2017-05-01T16:54:18Z")

</div>

Together with kirby-v2-lessphp - Less plugin for Kirby 2 it works!

---

<div class="post-metadata">

**Author:** ![mthiebou](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/mthiebou/32/10284_2.png) [@mthiebou](https://forum.getkirby.com/u/mthiebou)\
**Post date:** [May 1, 2017, 4:55pm UTC](https://forum.getkirby.com/t/generate-css-file-on-panel-update/7351/8 "2017-05-01T16:55:17Z")

</div>

```auto
kirby()->hook('panel.site.update', function($site) {

f::write( kirby()->roots()->assets() . '/less/style.less' , 

'@'. $site->colorbase()->key() . ':' . $site->colorbase() . ';' . "\n" . $site->less() , false);    
    
});

```

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 4:50pm UTC](https://forum.getkirby.com/t/generate-css-file-on-panel-update/7351/9 "2025-02-06T16:50:01Z")

</div>

Archived on February 6, 2025, 4:50pm UTC


