https://github.com/bolt/color
Color field extension
https://github.com/bolt/color
Last synced: about 1 month ago
JSON representation
Color field extension
- Host: GitHub
- URL: https://github.com/bolt/color
- Owner: bolt
- License: mit
- Created: 2020-08-06T09:47:50.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-03-25T12:33:25.000Z (about 4 years ago)
- Last Synced: 2025-04-16T07:15:11.746Z (about 2 months ago)
- Language: PHP
- Size: 25.4 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🎨 Bolt Color Field Extension
This extension allows you to use fields of `type: color` in your
ContentTypes, as defined in `contenttypes.yaml`.You can also manipulate colors in Twig, with all the might
of the [Iris PHP Color library](https://github.com/ozdemirburak/iris).## Installation
```bash
composer require bolt/color
```-------
## Usage
### Definition
In your `contenttypes.yaml`, you can define the following field:
```yaml
background:
type: color
label: Background color
```Which will show up as a colorpicker field like this (without red highlight):

### In twig
To get the hex value (`#ff0000`), simply use:
```twig
{{ record.background }}
```The [Iris library](https://github.com/ozdemirburak/iris) allows many ways
in which you can manipulate the value of the field, for example:```twig
{{ record.background.red }} {# get the amount of red #}
{{ record.background.values }} {# array with ['ff', '00', 'ff'] rgb values #}
{{ record.background.lighten(20) }}
{{ record.background.darken(10) }}
{{ record.background.dark }} {# true if color is dark #}
{{ record.background.hsl }} {# converts to HSL #}
{{ record.background.rgba }} {# converts to RGBA #}
```