Handle block assistants screw into HAML

I need to use some auxiliary elements of the handlebars block inside the element attribute. How can I get

.some.class{:class => "{{if property}} otherClass {{/if}}"} 

to disassemble correctly? Here is the compiled output as it is:

 <div class='class otherClass property}} some {{/if}} {{if'></div> 

I tried to slip away from every character other than a word, try single quotes and adjust the spacing, but it doesn't seem to fix anything. I hope to find a more elegant solution than just using the keyword: plain.

+6
source share
3 answers

I found that you need to add a character before {{}} for Haml to accept it. For instance:

 %div.some.class{:class => "a{{foo}}"} 

Not an idea, but a set of my goals.

+1
source

Actually, the trick does not work for any steering expression that is moderately complex.

In the end, I solved this using string literals in haml. So in the example shown in the question. A lower haml is required, remember to close the tag, which is the last line.

 \ <div class='class {{if property}} otherClass {{/if}} some '> -# Normal haml goes here and must not start at the same indent as the above literal \ </div> 
0
source

Move all classes to the class attribute instead of using both the shortened point and the class attribute.

 .col-md-12.card{ class: "{{toLowerCase level_name}}-master-card" } 

becomes

 %div{ class: "col-md-12 card {{toLowerCase level_name}}-master-card" } 

HAML 4.0.7

0
source

Source: https://habr.com/ru/post/916292/


All Articles