Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Setting colors to the value of a variable

I'd like to set the colors of my text and background according to the values of variables. Unfortunately, I can't figure out how to evaluate a variable inside custom style markup. The following code should illustrate what I am trying to do:
@

How can I achieve this?

Comments

  • edited September 2016
    Typical. I mess around for hours trying everything, finally give up and ask for help, and the very next thing I try ends up working. For future reference

    Make a widget as follows:
    <<widget "colortext">><<print "\@\@color:"+$args[0]+";background-color:"+$args[1]+";"+$args[2]+"\@\@>;><</widget>>
    
    and call it like so:
    <<colortext "red" "blue" "Ow! My eyes!">>
    
    Hexadecimal strings of the format "#FF00FF" work just fine too.
  • thebigh wrote: »
    Make a widget as follows:
    <<widget "colortext">><<print "\@\@color:"+$args[0]+";background-color:"+$args[1]+";"+$args[2]+"\@\@>;><</widget>>
    
    I'm unsure why you're escaping the custom style markup's at-symbols (), but you really don't need to do that.

    thebigh wrote: »
    Hexadecimal strings of the format "#FF00FF" work just fine too.
    Since you're actually setting CSS color properties, any valid CSS color value will work: color keywords, RGB hex triplet (i.e. #RGB or #RRGGBB), or the functional notations (i.e. rgb(), rgba(), hsl(), hsla()).
  • Yup, you're right, those backslashes weren't necessary.
Sign In or Register to comment.