Я использую haml со своим приложением направляющих, и у меня есть вопрос как самый легкий способ ввести этот haml код в файл HTML:
<div clas="holder">
<div class=top"></div>
<div class="content">
Content into the div goes here
</div>
<div class="bottom"></div>
</div>
И я хочу использовать его в своем haml документе как это:
%html
%head
%body
Maybee some content here.
%content_box #I want to get the code i wrote inserted here
Content that goes in the content_box like news or stuff
%body
Существует ли более легкий способ сделать это?
Я получаю эту ошибку:
**unexpected $end, expecting kEND**
с этим кодом:
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
def content_box(&block)
open :div, :class => "holder" do # haml helper
open :div, :class => "top"
open :div, :class => "content" do
block.call
open :div, :class => "bottom"
end
end
end
Вы также можете использовать haml_tag
def content_box
haml_tag :div, :class => "holder" do
haml_tag :div, :class => "top"
haml_tag :div, :class => "content" do
yield
haml_tag :div, :class => "bottom"
end
end
и в haml
%html
%head
%body
Maybee some content here.
= content_box do
Content that goes in the content_box like news or stuff
Типичное решение - использовать частичное.
Или вспомогательный метод в вашем файле _helper.rb:
def content_box(&block)
open :div, :class => "holder" do # haml helper
open :div, :class => "top"
open :div, :class => "content" do
block.call
end
open :div, :class => "bottom"
end
end
И в haml:
%html
%head
%body
Maybee some content here.
= content_box do
Content that goes in the content_box like news or stuff