Reputation: 741
Is it possible in HAML to use haml in haml like templates?
example:
page1 for example:
haml: menu.haml
%p
content
as you know, get our layout from layout.haml (like a banner and such). I want to make a seperate menu part in a haml file. Is this even possible?
extra info:
Upvotes: 2
Views: 1865
Reputation: 652
You can add partials as embedded haml
inside existing template:
For example, you have a view file called view.html.haml
:
%h2 This is the first view
%h4 the following line 'inserts' an external code inside the view
=render 'partial'
%h4 this text will appear next of partial
end the partial code partial.html.haml
:
%p
%span This is the external code
so, the final view when it is compiled will be:
%h2 This is the first view
%h4 the following line 'inserts' an external code inside the view
%p
%span This is the external code
%h4 this text will appear next of partial
The text inside quotes next render
y the path to partial inside app/view
folder in Rails without file extension, and you can add options, such as :layout
or :partial
. About Sinatra the path to partial works as the same way, just change the views path.
Upvotes: 1
Reputation: 176
Yes, you can even render haml partials like so:
= render :partial => "sidebar"
Upvotes: 1
Reputation: 992
Sure
= Haml::Engine.new(menu.haml).render(self)
Where self
is current context in your view files
Upvotes: 1
Reputation: 10997
Yes. Assuming menu.haml
in located in your views directory, and assuming it takes no locals, it's as easy as this:
= haml :menu
Upvotes: 4