[personal profile] kaigou posting in [community profile] style_system
Is it possible to set a variable to be another variable?

That is, instead of:

set color_thing = "#333366";

doing:

set color_thing = $*some_other_thing;

such that the default value of $*color_thing is equal to the value of $*some_other_thing, but with option for user to override?

Date: 2009-11-17 05:47 pm (UTC)
zvi: self-portrait: short, fat, black dyke in bunny slippers (Default)
From: [personal profile] zvi
Yes, at the theme level, you can do that.

Date: 2009-11-17 06:39 pm (UTC)
branchandroot: oak against sky (Default)
From: [personal profile] branchandroot
Right inside your print_stylesheet function, you should be able to require that variable x equal variable y. But that would screw with the ability of the user to select something totally different if that's what floats their boat. So I guess either you want to frame your x=y statement in such a way that if the values are changed they decouple, or else just set both variables to the same thing up in the settables list. *rueful* I usually go with the latter, despite it being longhand, as it were.

Date: 2009-11-17 06:42 pm (UTC)
zvi: self-portrait: short, fat, black dyke in bunny slippers (Default)
From: [personal profile] zvi
Hmm. Oh, you know, I've never actually tried to do it as a straight substitution. I've always done it through CSS, and you don't get the user over-riding them being connected that way.

thing-x { color: $*color-thing-y; }

Sorry for not thinking it through.

Um, I don't think you can temporarily define functions in themes? I know that you can create variables inside the print stylesheet functions, though. I don't know exactly how it's done, alas.

Date: 2009-11-17 08:29 pm (UTC)
zvi: self-portrait: short, fat, black dyke in bunny slippers (Default)
From: [personal profile] zvi
Yes, that's true.

The thing that I don't think you can do, which I think you want to do, is say set this_value=y and in a function, set user_controlled_value=this_value

And then have there be an effect when the user changes the user_controlled_value through the wizard. I could be wrong about that, though.

Date: 2009-11-18 02:36 am (UTC)
afuna: Cat under a blanket. Text: "Cats are just little people with Fur and Fangs" (Default)
From: [personal profile] afuna
You can set properties to other properties on prop_init, but I'm not sure about the particular scenario you're proposing, since usually what we do is check whether $*Y has been set; if it has, we use the user-defined value. If it hasn't, we use the fallback value. So something like this:

layout:
property Color X { des = "base value" }
property Color Y { des = "falls back on base value if not provided" }
set X = "blue"
set Y = ""


function prop_init() {
    if ( $*Y == "" or not defined $*Y ) {
        # Y has no value, let's fill it in 
        $*Y = $*X
    }
}

Profile

Dreamwidth style system discussion

June 2025

S M T W T F S
1234567
891011121314
15161718 1920 21
22232425262728
2930     

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 27th, 2025 07:38 am
Powered by Dreamwidth Studios