variable in class name jade

前端 未结 4 1699
悲&欢浪女
悲&欢浪女 2020-12-25 11:03

I can\'t set a variable name in a class in jade:

.flag_#{ session.locale } #{ session.locale }

I have:

相关标签:
4条回答
  • 2020-12-25 11:21

    Here's another approach:

    mixin formButton(text, type, extra_classes)
        - var default_classes = 'btn btn-primary'
        if extra_classes
            - var classes = default_classes + ' ' + extra_classes
        else
            - var classes = default_classes
    
        if type
            button(class=classes type=type) !{text}
        else
            button(class=classes type="submit") !{text}
    


    Example 1:

    Usage:

    +formButton('Text')
    

    Result:

    <button type="text" class="btn btn-primary" type="submit">Text</button>
    


    Example 2:

    Usage:

    +formButton('Text', 'button')
    

    Result:

    <button type="text" class="btn btn-primary" type="button">Text</button>
    


    Example 3:

    Usage:

    +formButton('Text', 'button', 'extra-class')
    

    Result:

    <button type="text" class="btn btn-primary extra-class" type="button">Text</button>
    
    0 讨论(0)
  • 2020-12-25 11:29

    Try this (have not tested):

    div(class="flag_#{ session.locale }") session.locale
    
    0 讨论(0)
  • 2020-12-25 11:33

    As for pug@2.0.0-alpha3 works this way:

    div(class="flag_" + session.locale) session.locale
    
    0 讨论(0)
  • 2020-12-25 11:33

    You can also use conditional statements to do this like

      if liked == true
        span.like.active
      else
        span.like
    
    0 讨论(0)
提交回复
热议问题