Generate a color preview in the data object tree

It might be helpful for others so I decided to share the piece of code I wrote tonight. I have a list of colors (Pantones) and I wanted to display a color preview in the data object tree. I followed this doc : https://pimcore.com/docs/6.x/Development_Documentation/Objects/Object_Classes/Class_Settings/Custom_Icons.html

And tadaaam :blush:

Heres the in my AdminStyle-extended class :

The other reason I wanted to share this with you is that I struggled on a weird issue. I used the hex value in the filename but I hadn’t noticed that it was appending a hash sign (#)… Problem was the hash has a very specific meaning in the URL format as you probably already know. So I you can’t figure why your asset doesn’t load, double check you save a correctly formed URL!

4 Likes

Now that’s a COOL feature! I also like the tooltip functionality which can be added for quick preview.

Will have to up my game in that regard. I thought just adding simple icons is enough. :smiley:

1 Like