Questions tagged [slim-lang]

Slim is a lightweight template engine for Ruby whose goal is reduce the syntax to the essential parts without becoming cryptic.

Slim is a template language whose goal is reduce the syntax to the essential parts without becoming cryptic.

The initial design of Slim is what you see on the home page. It started as an exercise to see how much could be removed from a standard html template (<, >, closing tags, etc...). As more people took an interest in Slim, the functionality grew and so did the flexibility of the syntax.

Slim will strive to maintain simplicity, but not everyone's definition of a readable syntax is the same. The docs will show you the options.

Slim uses Temple and Tilt. If you want to learn how Slim works, you'll need to study these projects.

Source: Slim-lang.com (About)

681 questions
109
votes
5 answers

erb, haml or slim: which one do you suggest? And why?

I am learning Rails and I have seen these template engines. I have no experience with them (only erb). But as I am a beginner, I am really confused. Which one do you suggest and why? Erb, Haml or Slim? Please tell your reason for preferring one over…
Omid Kamangar
  • 5,768
  • 9
  • 40
  • 69
108
votes
3 answers

slim dynamic conditional class

Just to help other developers, because there is no similar question on SO. div class=(is_active? ? 'active' : 'inactive') div class=('active' if is_active?)
Sergey Alekseev
  • 11,910
  • 11
  • 38
  • 53
61
votes
4 answers

Best way to handle data attributes in Slim

I was evaluating Slim as a replacement for HAML in a personal project, and it doesn't appear to handle HTML5 data attributes as gracefully as HAML. I was hoping someone may have also run into this, or may have known about an option/syntax I haven't…
mmoss
  • 713
  • 1
  • 5
  • 5
52
votes
3 answers

How to access instance variables in CoffeeScript engine inside a Slim template

I have a Rails controller in which I am setting a instance variable - @user_name = "Some Username" In my .slim template I am using coffee engine to generate javascript and want to print out the user name from client-sie javascript code - coffee: …
kapso
  • 11,703
  • 16
  • 58
  • 76
52
votes
6 answers

Dynamic class name

How to generate dynamic class name? li v-for='obj in objs' | {{ obj.id }} {{ obj.title }} div id="obj-{{ obj.id }} " style="float:right; color:red;" This sample doesn't work! I need this class name to update the div later!!!
NeverBe
  • 5,213
  • 2
  • 25
  • 39
36
votes
7 answers

How to embed dynamic Ruby code to "javascript" section in Slim templates?

One way: javascript_tag do == "var all_product_ids = #{existing_ids.to_json};" == "var products_json = #{@filter.data.to_json};" or: = %Q{ var all_product_ids = #{existing_ids.to_json}; var products_json = #{@filter.data.to_json}; } are…
wkang
  • 411
  • 1
  • 6
  • 12
36
votes
3 answers

ruby inside javascript block [slim template]

There is a way to put ruby conditions inside javascript block? i.e. javascript: var config = { common_value_1 : 1, common_value_2 : 2 }; - if my_value === true # this must be a ruby condition config.custom_true_value_1 = "1"…
norman784
  • 2,201
  • 3
  • 24
  • 31
36
votes
3 answers

Ruby Slim - How do you define an element's class with a rails helper or variable?

In rails slim (http://slim-lang.com/) the syntax for defining a new div with a class name "sample" is the following: .sample = "Content goes here" this will create:
Content goes here
I want to define a…
jay
  • 12,066
  • 16
  • 64
  • 103
29
votes
2 answers

Ruby on Rails - Make Slim the Default Template

I am working on a Ruby on Rails project and am needing to customize default views provided by Gems. The requirement is to use Slim for template. I understand that ERB is the default template engine for Rails. As per my observation, the priority is…
Ziyan Junaideen
  • 3,270
  • 7
  • 46
  • 71
21
votes
2 answers

Difference between single and double equals in Slim (= vs ==)

In Slim, when should I use double equals sign? For example: == yield == render 'partial' == stylesheet_link_tag "application", media: "all" title == full_title(yield(:title)) - flash.each do |key, value| == value or = yield = render…
Dan
  • 1,274
  • 2
  • 15
  • 32
19
votes
1 answer

Case statement in Slim

Is there a way to write a case statement in Slim for the following example. I made some changes for the StackOverflow question: How to write a switch statement in Ruby case a when 1..5 = "It's between 1 and 5" when 6 = "It's 6" when String =…
Ziyan Junaideen
  • 3,270
  • 7
  • 46
  • 71
18
votes
2 answers

Remove HTML tag attribute in slim when attribute should not be displayed

I would like to remove class attribute when class should not be displayed in Slim. In ERB, I could use: /> How do I do this in Slim? I found this, but I feel there must be a more idiomatic solution: |…
Piioo
  • 759
  • 10
  • 24
17
votes
5 answers

How to render HTML inside Slim templates

I'm trying to render a link preceded by an icon. I'm using Slim templating engine along with Bootstrap CSS. Usually you could do this the following way: My Profile According to Slim's documentation, we can…
Mohamad
  • 34,731
  • 32
  • 140
  • 219
16
votes
2 answers

How to put a hyperlink in the middle of a paragraph using the slim templating language?

How do you write the following in the slim templating language?

Join the Google group and let us know what you think, or what other features you’d like to see.

I tried the following: p ' Join the a href="" Google Group '…
Erik
  • 4,268
  • 5
  • 33
  • 49
14
votes
1 answer

Specifying a layout and a template in a standalone (not rails) ruby app, using slim or haml

I'm trying to do something like this in a standalone (not rails) app: layout.slim: h1 Hello .content = yield show.slim: = object.name = object.description I can't figure out how to specify a layout and a template. Is this possible with slim (or…
chrismealy
  • 4,830
  • 2
  • 23
  • 24
1
2 3
45 46