ERb, Markdown, and partial

Hi there – I’m trying to include an erb partial within a markdown file. When the markdown file gets processed, the HTML that’s contained within the partial is rendered as preformatted. I believe I’ve named my file properly, page.html.md.erb. I’ve tried changing the extension order to no avail. I’m using the default, Kramdown, but also tried Redcarpet just to see.

source/page.html.md.erb

<%= partial(:sidebar, :locals => { :active => 1 }) %>

Markdown here

source/_sidebar.erb

    <!-- Menu toggle 1 -->
    <a href="#menu" id="menuLink" class="menu-link">
...

page.html

      <pre><code>&lt;!-- Menu toggle 1 --&gt;
&lt;a href=&quot;#menu&quot; id=&quot;menuLink&quot; class=&quot;menu-link&quot;&gt;

...

What am I missing?! Any help would be appreciated.

Thanks for your help in advance!

Best,

Ashley

Name page.html.md.erb means: first process ERB, then Markdown, and the end result will be HTML. So the process you described is OK – first the ERB partials will be included, with all HTML tags, and then they will be processed with Markdown, which will turn them into a kinda citation.

The other way (page.html.erb.md) is not possible, since Markdown engine is not designed to process Middleman (or other) helpers, functions, code. You should include your partials with the help of a layout file (you can help yourself with frontmatter in .md to inform the layout what to include).

To put it simply, Markdown is designed to be the last one, mostly text with some formatting and some limited elements: links, images, tables.

Cool, thanks for the guidance!

For anyone else who runs into this… I ended up moving my partial into my page-specific layout. I could easily pass the necessary values to it via frontmatter as opposed to the partial locals.