Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I include an arbitrary file into a HAML template?

I want to have independent .markdown files that I then include in my haml templates. So I want to somehow include -- not render -- an external file into the template. I want the parent file to have :markdown in it, with the inclusion directly below that, and then the .markdown file to just be pure markdown.

Or: Is there a way to just use markdown as a rails template language (same way i can write templates or partials in erb or haml and rails just figures it out)?

like image 932
John Bachir Avatar asked May 18 '11 23:05

John Bachir


1 Answers

This is similar to your solution, but using the :markdown filter. Haml does string interpolation on any filtered text, so you can read the markdown file like this.

:markdown
  #{File.read(File.join(File.dirname(__FILE__), "foo.markdown"))}

You could put this into a helper, but you'd have to be careful with the file paths.

like image 58
matt Avatar answered Sep 22 '22 17:09

matt