0

I am trying to create a mixin that will set a var with a dynamic name.

// less File B
.varMaker(@varname, @value){

  // Here I would like to set a var with the name @varname 

}


// less File A
.varMaker(foo,bar);

My mixin is defined in a file B and called in a file A.

In File A I'd like to use the returned var like this :

// less File A
.varMaker(foo,bar);
background: @foo;

// I would like it compile in
background : bar;

I precise that I can not display the property and its value directly in my .varMaker mixin because after setting @foo var, it is supposed to be pass to an other mixin.

I succeed to use dynamic var name and a mixin that set a var separately but I am not able to do both.

I am compiling less code using php oyejorge and errors messages are not always explicit.

Ousmane
  • 2,673
  • 3
  • 30
  • 37
  • 1
    "because after setting `@foo` var, it is supposed to be pass to an other mixin." - Then you probably need to expand your example to illustrate this too. Usually the need for "dynamic" variable thing reveals underlying [XY-problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). I.e. you need to set value of `bar` to `background` property and pass the same value to a mixin, now why do you need any variable for this at all? And why should this variable have unique name each time? Either way see http://stackoverflow.com/questions/36868658. – seven-phases-max May 03 '16 at 20:42
  • Or yet in other words, why exactly instead just `@foo: bar;` you'd need `.varMaker(foo, bar);` doing the same? – seven-phases-max May 03 '16 at 20:46
  • I did not know the concept of XY-problem... very interesting ! I think you are right indeed. Il will reconsider the all thing ;) – Ousmane May 05 '16 at 12:42

0 Answers0