Shopify / Shopify/liquid

Replace colors swatch

Open
#1,463 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
11.9k
Forks
1.5k
Avg merge
17h 55m
Merged PRs (30d)
3

Description

Hi, i have a textarea with a list of color / hex value, example
negro #000
rojo #f00
blanco #fff

This value i convert to array with this:
assign colors = settings.swatch_colors_list | newline_to_br | strip_newlines | split: "
"

In each option values check if the option is Color then wanna check if the value color is in the colors array, i have this:

{% if option.name == 'Color' or option.name == 'color' %}
{%- liquid
assign colorp = value | downcase | escape | strip // THIS IS THE OPTION COLOR
for c in colors

  assign eachcolor = c | uniq | split: " #"
  
  for ec in eachcolor
    if ec[0] == colorp
      assign bg = ec[1]
    endif
  endfor

endfor

%}

data-color="{{ colorp }}"
data-bg="{{ bg }}"
{% endif %}

but simple i dont have put in bg the correct value :-( i try many options but i can't do it, can help me?

the idea is to have a textarea in the theme where the client can put a list of colors and this is replaced by a hexadecimal that he can put

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Liquid template snippet with the textarea values and color options described in the issue. Trace how the colors array, eachcolor, colorp, and bg are evaluated. Done means the configured color name reliably maps to its hexadecimal value in data-bg.

Written by the indexing model from the issue text.

Assessment

Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.