jay
jay

Reputation: 12495

Slim Syntax for Inline Div/Table Classes with Embedded Ruby

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="<%[email protected]%>">

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.

Upvotes: 2

Views: 4261

Answers (2)

Alexander Presber
Alexander Presber

Reputation: 6635

According to the documentation here you can achieve this as follows:

td [email protected]

Btw., when writing td.class1 class=some_ruby_exprthe two classes will automatically be merged into the resulting class attribute.

Upvotes: 1

Vasiliy Ermolovich
Vasiliy Ermolovich

Reputation: 24617

The doc for this feature is here:

td class="#{@article.attribute}"

Upvotes: 4

Related Questions