Slim Syntax for Inline Div/Table Classes with Embedded Ruby
-
27-06-2021 - |
Question
I have a table defined in slim:
table
tr
td
=_("Some Content")
td
=_("Some Content")
I would like to add some classes to certain td tags. I can do so like this:
table
tr
td.extraclass
=_("Some Content")
td
=_("Some Content")
This adds "extraclass" to that td:
<td class="extraclass"> Some Content </td>
How can I add a class by embedding some rails/ruby into this? In normal rails I could do:
<td class="<%=@article.attribute%>">
How do I do this here? I don't think I can do:
td.=_(@article.attribute)
But I would like to add classes in some similar way here. Anybody have any advice? if I have not been clear in what I'm attempting to do, please let me know what I can add.
Solution
The doc for this feature is here:
td class="#{@article.attribute}"
OTHER TIPS
According to the documentation here you can achieve this as follows:
td class=@article.attribute
Btw., when writing td.class1 class=some_ruby_expr
the two classes will automatically be merged into the resulting class
attribute.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow