I’m using middleman to do some rapid prototyping and can’t for the life of me figure out how to include one HAML file into another HAML file.
I can include stuff in a layout file, but can’t get one non-layout file to include another non-layout file. There are blocks of HTML that I want to reuse on some pages and I think I could do this. I’ve tried:
- render: partial=>"shared/nav.haml"
=shared/nav.html
="shared/nav.html
and none of these work.
Am I missing a config option or plugin? This is a fresh middleman install.
ANSWER
Partials may need file names that start with an underscore. My partial is placed in a folder called shared. The full name of the file is _nav.html.haml
This worked for me.
!= haml :"shared/_nav"
Example in context:
#email.main.subscriber.resize
#bg-wrap
%div
%img{:src=>"images/backgrounds/image.png",:alt=>""}
%section#zone10
!= haml :"shared/_nav"
You may also use the format specified in the approved answer below.
I’ve been using HAML with MiddleMan and couldn’t be happier. Here is what is working for me:
I have a file:
source/_donate_buttons.hThis uses the partial statement shown to include a file called
source/_paypal_donate_button.html.haml.And I include the
_donate_buttons.html.hamlfile itself in a couple of places with:though I think this could also be:
I.e. I think
partialis the magic you’re looking for.And, just for completeness, here is a slightly stripped down
_paypal_donate_button.hamlwhich shows how the paramaterization works there:Fwiw, I don’t think the file needs to be
_filename.html.hamland can instead be_filename.haml. Also, I’m localizing these, so ignore the t(‘tagname’) and just put strings there. (I didn’t want to introduce an error copy-pasting the examples so I left them in there.)Hope this helps!