Hi, Sonja, thank you for the reply.
What code do you mean?
header.php is calling less.php snippet
<?php if($site->stylingSwitcher() == "true"): ?>
<?php snippet('less') ?>
<?php endif ?>
And less.php snippet is connecting site.yml options to lessphp plugin
...
// various options
...
// Activate library.
require_once 'site/plugins/lessphp/lib/Less/Autoloader.php';
Less_Autoloader::register();
$parser = new Less_Parser($options);
// Compile content
$parser->parseFile($sourceFile);
// Variables modification
$parser->ModifyVars(
array(
'@global-font-family'=>h($site->textFontFamily()),
'@global-font-size'=>h($site->textFontSize()) . 'px',
'@global-primary-font-family'=>h($site->headingFontFamily()),
'@global-primary-font-weight'=>h($site->headingFontWeight()),
'@global-secondary-font-family'=>h($site->secondaryFontFamily()),
'@global-secondary-font-weight'=>h($site->secondaryFontWeight()),
'@global-secondary-font-style'=>h($site->secondaryFontStyle()),
'@global-color'=>esc($site->textColor()),
'@global-emphasis-color'=>esc($site->textEmphasisColor()),
'@global-muted-color'=>esc($site->textMutedColor()),
'@global-link-color'=>esc($site->textLinkColor()),
'global-inverse-color'=>esc($site->inverseColor()),
'@global-background'=>esc($site->defaultColor()),
...
// And so on
...
And it compiles many .less files from assets/app/
folder, combining those variables values.
It does some caching, but I can not do caching of those variables from site.yml so for as long the switch in site.yml is turned on (true) it compiles on every page refresh. Only when switch is off, snippet isn’t called.
It actually works great, but I am a perfectionist, and I know some users will forget to turn it off.
So, best would be to run/activate that snippet on selected fields save. Or to have a button with Janitor field.
But I didn’t find anywhere in the docs or in the forum that anybody called snippet from hook, or anywhere else except the template file.
My code in its best got this far
'bnomei.janitor.jobs' => [
'aweSomeItCouldBe' => function (Kirby\Cms\Page $page = null, string $data = null) {
F::load($kirby->root('snippets') . 'less.php');
return [
'status' => 200,
'label' => 'Success',
];
},
]
The same and various similar things I tried also with site.update:after
hook.