Methods that can be used directly from a UI Kit object.
If you are using helpers you can replace
$uikit->
with aget_ui()->
.
A Constructor has one paramater - $config, that can be an array or Config object.
use RobiNN\UiKit\UiKit;
$uikit = new UiKit();
Get instance.
There is one paramater $config, which is the same as in the constructor.
use RobiNN\UiKit\UiKit;
$uikit = UiKit::getInstance();
Get CSS framework options using "dot" notation.
$alert_default = $uikit->getFrameworkOption('alert.colors.default');
// alert-primary - if is used BS5
Set CSS framework options using "dot" notation.
$uikit->setFrameworkOption('alert.colors.default', 'blue');
// blue - .blue class for all CSS frameworks
$uikit->setFrameworkOption('alert.colors.default', 'blue', 'bootstrap5');
// blue - .blue class only for BS5
Render template.
echo $uikit->render('tpl_name', []);
// Set true on the last parameter to enable loading templates from variable
echo $uikit->render("{{ alert('Example') }}", [], true);
Set path with templates.
https://twig.symfony.com/doc/3.x/api.html#built-in-loaders
$uikit->addPath(__DIR__.'/templates', 'path_namespace');
Get component's object.
$alert = $uikit->getComponent('alert');
Register new component.
$uikit->addComponent('example_component', ExampleComponent::class);
More detailed into can be found here.
Get a UI Kit object.
This helper function can be used to easily access a UI Kit object, and after overriding can set in it custom config. By default, this function uses default config.
Example, access to a config object:
$fw = $uikit->config->getFramework();
Set component options.
echo $uikit->alert('example')->options([]);
Set component attributes.
echo $uikit->alert('example')->attributes([]);
Render component.
There is no need to use this if you are calling the component with echo or casting it to a string, as PHP will do this automatically.
echo $uikit->alert('example');