Rails: Arbre yield content for

From FVue
Jump to: navigation, search

Problem

Within Arbre, the normal yield :foo doesn't display output captured like:

content_for :foo do
  span 'bar'
end

Instead, wrongly, span 'bar' is output immediately within the Arbre template, and yield :foo renders nothing.

Environment

  • rails-7

Solution

Within content_for, wrap the output in Arbre::Context and convert to string (to_s):

content_for :foo do
  Arbre::Context.new do
    span 'bar'
  end.to_s
end

Now within an Arbre template, use text_node or content_for to output the captured content:

text_node yield(:foo)
text_node content_for(:foo) # Alternative notation

Comments

blog comments powered by Disqus