andersamer
andersamer

Reputation: 167

Is it possible to set a LESS mixin parameter to a variable?

This could have a very simple answer that I probably have missed, but if you had a mixin like so...

.mixin(@param1: 'foo'; @param2: #bbaarr); {
    font-family: @param1;
    color: @param2;
}

...would you be able to replace the values of @param1 and @param2 with other pre-defined, global variables (as shown below)?

@foo: 'foo';
@bar: #bbaarr;

.mixin(@param1: @foo; @param2: @bar); {
    font-family: @param1;
    color: @param2;
}

If I have any basic syntax errors, please understand. I literally learned LESS about an hour ago. :)

Upvotes: 0

Views: 23

Answers (1)

Luca Detomi
Luca Detomi

Reputation: 5716

Simply remove ; at the end of mixin heading.

Please see the following:

@foo: 'foo';
@bar: #fff;

.mixin(@param1: @foo; @param2: @bar) {
    font-family: @param1;
    color: @param2;
}

.foofoo {
 .mixin;
}

that compiles into:

.foofoo {
  font-family: 'foo';
  color: #fff;
}

Upvotes: 1

Related Questions