Search code examples
ruby-on-railsangularjsslim-lang

Slim template interprets {{myJsVar}} as HTML attribute grouping


I'm playing around with Angularjs and Slim but am trying to figure out how to come up with a cleaner syntax.

I want to do:

td {{content.name}}
td {{content.body}}
td {{content.owner}}

But it gives me an error. Most likely because { is used to group HTML attributes. I've had to change it to this:

td
  | {{content.name}}
td
  | {{content.body}}
td
  | {{content.owner}}

Is there a cleaner way to do this?


Solution

  • The change that allows this is in slim version 2.0.3.

    You can add the following in config/initializers/slim.rb:

    Slim::Engine.set_options :attr_list_delims => {'(' => ')', '[' => ']'}
    

    This removes { from the defaults. See the doc here and search on the page for attr_list_delims.