Set LESS variable if it's not set -


is possible set less variable given value, if hasn't been defined?

i can seem find solutions sass.

an important remark: turns out need such trick happens xy-problem (as result of misunderstanding less variable semantics). there's no real use-cases want (in less instead always define default value (so exists) overridden @ will). before using trick below, make sure it's not something else want actually.


it quite simple (since v1.4.0) if need provide such variable same scope (i.e. global or local) defined:

@bar: 41; // comment/uncomment test  .define-bar-if-not-defined() {@bar: 42} .define-bar-if-not-defined(); // exposes variable if it's not in scope  #using-global-bar {     global-bar: @bar; }  #using-local-bar {     @bar: 43; // comment/uncomment test     .define-bar-if-not-defined();      local-bar: @bar; } 

however method won't work if try use global/parent scope variables used in local scope (and may problem if need generic method when you're not sure scope original variable possibly come from):

#using-unknown-bar-in-local-scope {     // ... code ...      .define-bar-if-not-defined(); // won't override local @bar (if any) overrides global , parent scope @bar      bar: @bar; } 

in case don't know straight-forward solution (w/o inline javascript hacks 1 use in guard expression example)


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -