hey all,
My index.html.haml:
- wrap do
- page_title “Teams List View”
application_helper.rb:
def page_title(title)
content_tag :h1, title
end
def wrap(&block)
concat(content_tag(:div, capture(&block), :class =>
“generic_header”))
end
I load in browser and get:
Teams List View
Teams List View
It’s rendered twice. Not sure why. I invoke the wrap iterator, passing
a block into the argument list, wrap receivers it as a reference, then
I concat a div, use capture to render the page title as nested within
div, and assign div class. Not sure what I am doing wrong.
What happens if you get rid of concat()?
thanks for response, and the explanation of capture(). When I removed
the concat from the helper, the title stopped rendering twice. I
thought the concat was used to concatenate the two blocks of html, but
after reading documentation it appears it’s to render haml without
using “=”.
By the way, if you put some html at the top of the page, e.g.
%p Index.html.haml
- wrap do
- page_title “Teams List View”
Your wrap() method will double render the whole page.
Based on my experiments with haml, I would never consider using a
multiline ruby block that contains a rails helper. The results are too
unpredictable. All of these syntaxes do what you want (without
concat):
= wrap {page_title “Teams List View”}
Curiously, this does not work:
- wrap {page_title “Teams List View”}
which doesn’t make any sense in light of the second syntax above.
Note that in this code:
content_tag(:div, capture(&block), :class =>“generic_header”)
…capture() does indirectly what block.call() does directly.
It seems to me that the = sign in haml is arbitrary and capricious. For
instance, how does the syntax:
- wrap do
- page_title “Teams List View”
result in anything being added to the page?