Best way to handle data attributes in Slim

前端 未结 4 799
自闭症患者
自闭症患者 2021-02-04 23:26

I was evaluating Slim as a replacement for HAML in a personal project, and it doesn\'t appear to handle HTML5 data attributes as gracefully as

4条回答
  •  -上瘾入骨i
    2021-02-05 00:18

    There are multiple ways in Slim

    1. As Hash

      Attributes which will be hyphenated if a Hash is given (e.g. data={a:1,b:2} will render as data-a="1" data-b="2")

    2. Use it directly as "mu is too short" mentioned, quite intuitive.

      a data-title="help" data-content="foo"
      
    3. Use Ruby code. I often do this and rarely above.

      = link_to 'foo', bar_path, data: {a: 'a', b: 'b'}
      

提交回复
热议问题