Reputation: 11
I created a layout with a variable inside.
layout.haml:
- title = "Example"
%title #{title}
It works perfect and gave me this:
<title>Example</title>
But, if I put this variable in a partial, it doesn't work
_vars.haml:
- title = "Example"
layout.haml:
=partial "vars"
%title #{title}
How can I define all the variables on an external document and make it work?
Thanks for the help
Upvotes: 1
Views: 851
Reputation: 3311
Maybe you could put your shared code in helper?
# application_helper.rb
def title
@title ||= 'Example'
end
After that title
helper could be used either in primary view or in partial. Notice that calculation of variable will be performed only once due to ||=
.
Upvotes: 0
Reputation: 1936
You are probably looking for content for:
layout.html.haml:
%title= yield(:title)
_my_partial.html.haml:
- content_for(:title) do
Example
Upvotes: 1