Hex color to rgb color converter for shopify
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



I needed to convert the colors values from the color picker in the theme settings form. So I made this quick hex2rgb liquid.

I couldn't find a quick solution for this that wouldn't require javascript. I wanted something I could just use in a css liquid. The advantage of css rgb colors is that you can add transparency. This is useful if you want to make the background of an element transparent without applying that transparency to all the child elements.

I hope someone finds this useful.

I'm sure the gods of Shopify can probably tweak this to be less code, but this works for me. It would be great if we could just shove this into a filter.


{% comment %}
    Assign a variable called "hex2rgb_hex" to the color you want to 
    convert.This is where you'd put the variable assignment from 
{% endcomment %}
{% assign hex2rgb_hex = settings.my_hex_color_var %}
{% include 'hex2rgb' %}
{% comment %}
    hex2rgb.liquid will return three variables hex2rgb_r, hex2rgb_g, 
    hex2rgb_b that you can apply these variables in your css rules.
    - Some other variables are also set, so beware of that.  All 
      variables are prefixed with "hex2rgb_" to try to avoid naming 
    - hex2rgb.pack.liquid will reduce the amount of whitespace 
      generated by calling the color converter.
{% endcomment %}
.my_element {
    background: rgb({{ hex2rgb_r }}, {{ hex2rgb_g }}, {{ hex2rgb_b }}, {{ settings.my_opacity_var }});