I have trouble understanding basic Slim syntax.
First question, how to do you enter new line (line break)?
Second request, could you please rewrite the following snippet, I suspect I didn't do it easy way?
- provide(:title, @course.title)
.row
aside.span4
section
h1 = @course.title.capitalize
=> link_to t('ui.edit'), edit_course_path(@course)
'|
=> link_to t('ui.back'), courses_path
p
b #{t('activerecord.attributes.subject.title')}:
| #{@course.subject.title}
p
b #{t('activerecord.attributes.student_level.title')}:
| #{@course.student_level.title}
h4 #{t('activerecord.attributes.course.objectives')}
= @course.objectives
This is its output:
tahrirlash (edit) | orqaga
Predmet nomi: english 5-7 year olds
O'quvchi darajasi: beginner
objectives b
What is Slim? Slim is a fast, lightweight templating engine with support for Rails 3 and later. It has been heavily tested on all major ruby implementations. We use continuous integration (travis-ci).
Definition of slim file : a file very narrow in proportion to its length.
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. These let you build complex pages without resorting to server-side languages like PHP.
For new line, you should just use br like:
h1 Line1 content
br
h1 Line2 content
And about the above mentioned code, it can be rewrite like this:
-provide(:title,@course.title)
.row
aside.span4
section
h1 = @course.title.capitalize
= link_to t('ui.edit'), edit_course_path(@course)
'|
= link_to t('ui.back'), courses_path
p
b = t('activerecord.attributes.subject.title')
|:
= @course.subject.title
p
b = t('activerecord.attributes.student_level.title')
|:
= @course.student_level.title
h4 = t('activerecord.attributes.course.objectives')
= @course.objectives
To insert br tag into some tag in slim:
Example 1. Slim template:
h1
| Hello
br
| world
It will produce html:
<h1>Hello<br>world</h1>
Example 2. Fragment of slim template for displaying form:
p
= f.label :title
br
= f.text_field :title
It will produce html:
<p>
<label for="question_title">Title</label><br>
<input name="question[title]" id="question_title" type="text">
</p>
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