oblik / kirby-variables
Easy language variable management in YAML files for Kirby.
Installs: 705
Dependents: 1
Suggesters: 0
Security: 0
Stars: 8
Watchers: 4
Forks: 0
Open Issues: 0
Type:kirby-plugin
Requires
Requires (Dev)
- oblik/kirby-tester: ^1.2
- phpunit/phpunit: ^8.3
README
Allows you to easily manage language variables by putting them in separate YAML files and nesting them.
⚠ Deprecated!
By putting variables in separate files, you aren't really gaining much. You'd be much better off having a "variables" or "texts" tab in your site.yml
and just putting simple text
fields in there, optionally with help text, placeholder, etc.
If you really need to load variables from a file, you could do it like this:
'translations' => Yaml::decode(F::read(kirby()->root('languages') . '/vars/en.yml'))
Or, alternatively, you could use bnomei/autoloader-for-kirby.
Installation
With Composer:
composer require oblik/kirby-variables
Usage
After you've installed the plugin and you open your site, the plugin will run and it will automatically get the variables from your PHP files and put them in YAML files in the same directory. After that, you can remove the variables from your PHP files, as they're no longer needed. Then, use the YAML files to manage your variables.
Your variables should continue to work as they did so far. In the YAML file, nested arrays are flattened and their keys are concatenated with a period (.
). For example, the following:
foo: bar: test baz: qux: test2
...is converted to:
Array
(
[foo.bar] => test
[foo.baz.qux] => test2
)
...and you can use the variables in your templates with t('foo.baz.qux')
.
Config
folder
Sets where the YAML files are stored:
'oblik.variables.folder' => function ($kirby) { return $kirby->root('content') . '/_variables'; }