Search code examples
htmlrubyerbpartialsmiddleman

Sending custom variables to partial - middleman


How do I send a custom variable to a partial with a call from the markup.

<%= partial (:contentHeader, :title=>"Title Goes here") %>
/*trying to send a variable named title with "Title Goes Here" to the partial*/

The partial is kind of like this:

<div class = "contentHeader">
<h2><%=title%></h2>
</div>

So the output should turn out to be

<div class = "contentHeader">
<h2>Title Goes Here</h2>
</div>

Solution

  • Use :locals to send variables to partial,

    <%= partial(:contentHeader, :locals => { :title => "Title Goes here" }) %>