Huangism
Huangism

Reputation: 16438

Can't extract the proper value in LESS

I have the following

@ext-colour-codes:
    038p #717370,
    0040 #dee0e1,
    041g #83111b,
    03t3 #333333,
    041w #313131,
    042a #4d4d4d,
    044j #2f637e,
    0a4d #666666;

@ext-colour-codes-total: 8;

My loop is as follow

.ext-colour-code-loop ( @l ) when ( @l > 0  ) {

    @item: extract( @ext-colour-codes, @l );
    @code: extract( @item, 1 );
    @colour: extract( @item, 2 );

    .ext-@{code} {
        background-color: @colour !important;
    }

    .ext-colour-code-loop( @l - 1 );
}

.ext-colour-code-loop( @ext-colour-codes-total );

The output I got is (only showing one for this example)

.ext-44j {....}

The 0 was stripped, as a matter of fact, none of the classes comes out as the original input. Some are 2 characters and some are 3. How do I prevent this from happening?

Upvotes: 1

Views: 67

Answers (1)

Daniel Moses
Daniel Moses

Reputation: 5858

Just make sure you code is treated as a string. Change all the 044j to ~"044j" so it's an escaped string.

Documentation: http://lesscss.org/features/#features-overview-feature-escaping

Upvotes: 2

Related Questions