Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 390
Brennan Cheung Avatar asked Jul 16 '13 21:07

Brennan Cheung


People also ask

What is Slim in HTML?

What's Slim? Slim is a page-templating language that minimizes markup and syntax. It removes most of the extra "programming-like" symbols from HTML so that your code looks cleaner. Slim also adds if-else statements, loops, includes, and more.

What is slim template?

Slim is a template language whose goal is to reduce the view syntax to the essential parts without becoming cryptic. It started as an exercise to see how much could be removed from a standard html template (<, >, closing tags, etc...).

What template engine does Rails use?

By default, Rails uses the Embedded Ruby or ERB templating engine. It lets you embed Ruby code directly in your HTML views. ERB is not the only templating engine though. The other two popular engines are Haml and Slim.


1 Answers

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.

like image 133
Tyler Collier Avatar answered Sep 20 '22 02:09

Tyler Collier