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?
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.
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...).
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With