presseddigital / colorit

A slick color picker fieldtype plugin for the Craft CMS control panel
Other
21 stars 8 forks source link

Possible to get array of all colors in a preset from Twig? #9

Closed cmalven closed 5 years ago

cmalven commented 5 years ago

I'd like to be able to fetch all of the colors in a given preset as an array, something like the following:

{% set colors = craft.colorit.colours.presetColours('Brand Colors') %}

Any existing way to do something like this?

samhibberd commented 5 years ago

@cmalven you can get this info in a couple of ways.

1) Through any custom field:

{{ entry.yourColourFieldHandle.field.paletteColors }}

2) By getting a craft field populated with the preset settings:

{% set field = craft.colorit.presets.getPresetbyId(4).getFieldType() %}
{{ field.paletteColors }}

You can grab a preset ID from the CP, will add a handle at some point.

cmalven commented 5 years ago

Thank you @samhibberd that's perfect.