How to Install and Use Slim Template Engine with Middleman

How to install and use Slim template engine with Middleman

So here we go... after much reading and searching google for examples I think I figured it out.

To get Slim working with Middleman

  1. Add gem "slim" to your project's gemfile
  2. go to command line, in your project folder and gem install bundler
  3. In the config.rb file add require 'slim'
  4. Start the middleman server to test it

Include a slim file in another slim file

Looks like it can be done in this way:

Slim::Template.new('template.slim', optional_option_hash).render(scope)

Found in slim readme: https://github.com/slim-template/slim

How to add html-file with JavaScript code in template Slim?

The best way to add some javascript to your slim file is either by including the javascript file using

= javascript_include_tag 'name of the file' 

or by directly adding the javascript code to your slim file, using

javascript:
code line 1
code line 2
...

Define custom title for calendar pages in MiddleMan

In the end, here's how I chose to proceed : in my calendar.slim and tag.slim templates, I simply defined a @title variable that I use in my default layout. In calendar.slim, I use the built-in variables year, month and day to build a title string, and in tag.slim, I use the built-in tagname variable.

[calendar.slim]

- case page_type
- when 'month'
- date = date_to_fr Date.new(year, month, 1).strftime('%B %Y')
- when 'year'
- date = year

- @title = "#{date} - Archives"

(...)

And then in the layout, I then use the following code to display my @title variable followed by my blog name, unless @title does not exist (then I just use my blog name as the page title) :

[layout.slim]

title
= "#{@title} | " unless @title.nil?
| Pierre-Adrien Buisson : Le Blog !


Related Topics



Leave a reply



Submit