我一直在将 HAML 与 MiddleMan 一起使用,并且非常高兴。这对我有用:
我有一个文件:source/_donate_buttons.h
#DonationButtons
%p= t('searching.donate_cover_costs')
%br
= partial(:paypal_donate_button, :locals => {:amount => 1,
:amount_text => t('searching.donate_1')})
这使用显示的部分语句来包含一个名为source/_paypal_donate_button.html.haml
.
我将_donate_buttons.html.haml
文件本身包含在几个地方:
= partial "donate_buttons"
虽然我认为这也可能是:
= partial :donate_buttons
即我认为partial
是你正在寻找的魔法。
而且,为了完整起见,这里有一个稍微精简的_paypal_donate_button.haml
部分,显示了参数化是如何在那里工作的:
-btnclass = (locals.key?(:highlight) && locals[:highlight] ? "HighlightedDonationButton" : "DonationButton")
-btnstyle = locals.key?(:button_style) && locals[:button_style]
.DonationButtonContainer
%form{:action => "https://www.paypal.com/cgi-bin/webscr", :method => "post"}
%input{:name => "business", :type => "hidden", :value => "payments@example.com"}
%input{:name => "cmd", :type => "hidden", :value => "_donations"}
%input{:name => "amount", :type => "hidden", :value => "#{amount}.00"}
%input{:name => "currency_code", :type => "hidden", :value => "USD"}
%input{:class => btnclass, :alt => t('paypal.alt_text'),
:style => "cursor: pointer; font-size: 18px; #{btnstyle}", :type => "submit", :value => amount_text}
Fwiw,我认为文件不需要_filename.html.haml
而且可以是_filename.haml
. 另外,我正在本地化这些,所以忽略 t('tagname') 并把字符串放在那里。(我不想在复制粘贴示例时引入错误,所以我将它们留在了那里。)
希望这可以帮助!