问题描述
我在个人项目中评估了 Slim 作为 HAML 的替代品,它似乎不能像HAML那样优雅地处理HTML5数据属性.我希望有人可能也遇到了这个问题,或者可能知道我在他们的文档中还没有找到的选项/语法.
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 HAML. I was hoping someone may have also run into this, or may have known about an option/syntax I haven't yet found in their docs.
HAML允许您仅使用嵌套散列来定义 HTML 5数据属性,如下所示:
HAML allows you to define HTML 5 data attributes simply by using nested hashes like so:
%a{data: {key1: 'val', key2: 'val'}}
导致
<a data-key1='val' data-key2='val'></a>
推荐答案
Slim中有多种方法
There are multiple ways in Slim
-
作为哈希
As Hash
直接使用它,因为提到的"mu is too short",非常直观.
Use it directly as "mu is too short" mentioned, quite intuitive.
a data-title="help" data-content="foo"
使用Ruby代码.我经常这样做,很少在上面.
Use Ruby code. I often do this and rarely above.
= link_to 'foo', bar_path, data: {a: 'a', b: 'b'}
这篇关于在Slim中处理数据属性的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!