Include a slim file in another slim file

Francesco Belladonna picture Francesco Belladonna · Sep 21, 2013 · Viewed 7k times · Source

I'm working on a static website (so no real server support) and I would like to include a small slim snippet in another, possibly passing a variable to it.

Is this possible? In rails is quite easy, though the render method, but I have no idea how to do it on slim (obviously load method doesn't work for slim).

Answer

Igor Springer picture Igor Springer · Apr 30, 2015

Slim contains Include plugin that allows to include other files directly in template files at compile time:

require 'slim/include'

include partial_name

Documentations is available here: https://github.com/slim-template/slim/blob/master/doc/include.md

If you need to include the files at runtime

Slim::Template.new("#{ name }.slim").render does the job (https://github.com/slim-template/slim#include-helper).