Save custom css to a file

If you want to try it, you can write to a file like this (assuming the custom CSS is stored in the site in a single field, so we use `site.update:after):

    'hooks' => [
        'site.update:after' => function($site) {
      
          $css = $site->custom_css_field()->value();
          F::write(kirby()->root('assets') . '/css/custom.css', $css);

        }
    ]

The example assumes, that the editor actually writes CSS into a field. If you store single values in different fields, you would of course have to create valid CSS first, then store all that in the file.

2 Likes