MauF
MauF

Reputation: 451

Less variables: @@var

Can someone please explain this variable example on the Less.org documentation:

It is also possible to define variables with a variable name:

@fnord: "I am fnord.";
@var: 'fnord';
content: @@var;

Which compiles to:

content: "I am fnord.";

The part that confuses me is the double @.

Thanks.

Upvotes: 1

Views: 1284

Answers (3)

donlaur
donlaur

Reputation: 1287

Very much like variable variables. Dynamic variables were you might not know the name of the variable or its value until you create it. I find the PHP examples very helpful to explain what is happening.

Let say you have a monster site and you do not know what the variable you will need. You don't want to include them all so at runtime you can produce the dynamic variable.

Without loops and the power you get from PHP, not sure the @@ is as helpful for the normal average user.

Upvotes: 0

GajendraSinghParihar
GajendraSinghParihar

Reputation: 9131

This statement explain itself

It is also possible to define variables with a variable name:

So: content: @@var; is actually content: @fnord; which is content: "I am fnord.";

NOTE: You can consider @@ as a pointer notation @ as a variable

Upvotes: 5

Guffa
Guffa

Reputation: 700192

The @var part of content: @@var evaluates to the value of the @var variable which is fnord, which makes it content: @fnord.

The @fnord part in turn is evaluated as the value of the variable @fnord which is "I am fnord." making it content: "I am fnord."'

Upvotes: 2

Related Questions